What is the most suitable data type for latitude / longitude in Realm for React Native?

I am trying to determine what is the most optimal choice for a Realm object diagram that should store the properties of latitude and longitude.

From my point of view, the ideal data type (if I used something like swift) would be a signed data type with an accuracy of 6.

It doesn't seem like the precision of the number can be controlled with React Native, which is to be expected since it maps to a Javascript object, but it’s still not clear to me what kind of choice this is.

From the Realm documentation for React Native:

int, float and double properties are mapped to JavaScript Number objects. Internally, "int" and "double" are stored as 64 bits, while a float is stored with 32 bits.

Realm Docs - Basic Property Types

I assume that floatthere is a right choice, but it is not clear to me that this is the right answer. Any thoughts from someone who has come across how realm handles these data types are greatly appreciated.

+4
source share
2 answers

Float- right choice. 32 bits are sufficient to store latitude and longitude, and it will be more efficient.

+1
source

In my application, I need to round to three decimal places. I found that I Floatcaused rounding errors, but Doublenow it works with the expected accuracy.

0
source

Source: https://habr.com/ru/post/1656262/


All Articles