SparkFun Forums 

Where electronics enthusiasts find answers.

Discussions about carrier boards have here!
User avatar
By R34220
#236725
I am trying to understand how to convert GPS coordinates from google maps to use in one of the example sketches.
SparkFun u-blox GNSS Arduino Library -> Example17_Geofence

Google Maps coordinates : 40.68947716486538, -74.04446821564673

How to I convert these use with the SparkFun_u-blox_GNSS_Arduino_Library
Code: Select all
Serial.println(myGNSS.addGeofence(latitude, longitude, radius, confidence));
User avatar
By YellowDog
#236739
The coordinates you have in your post are decimal degrees and the sparkfun library appears to use those as well.
The example appears to be looking for a coordinate with 7 positions after the decimal place so all you need to do is drop everything after the 7th decimal.
40.68947716486538, -74.04446821564673
These have 14 positions after the decimal so you're going to chop off the last 7 getting this:

40.6894771, -74.0444682

Also, you need 4 sets of coordinates to create a box around what you're defining a fence around according to the example.
User avatar
By R34220
#236758
myGNSS.getLatitude() or myGNSS.getLongitude() never has any decimal point. There must be some conversion which I am unable to figure out.
One of the remarks say "Get the longitude in degrees * 10^-7" so I believe I need to know how to do the conversion backwards with values like 40.68947716486538, -74.04446821564673.
By jremington
#236759
myGNSS.getLatitude() or myGNSS.getLongitude() never has any decimal point
Were you expecting a text string? The coordinates are stored internally either as floating point variables (declared double or float) or as 32 bit integers, in degrees*(1 or 10) million.

Post the code, using code tags.
User avatar
By R34220
#236762
Sorry, I am not explaining it right. As another example, the "Example31_Great_Circle_Distances" sketch. In it the SparkFun offices is used ....
Code: Select all
static const long TARGET_LAT = 400909142, TARGET_LON = -1051849833; // SparkFun's location: degrees * 10^-7 (40.091 N, 105.185 W)
    
https://www.google.com/maps/place/40%C2 ... 4d-105.185

Tells me the location is 40.091000, -105.185000. what formula is used to convert to the same values used in the sketch ( 400909142, -1051849833)?
By jremington
#236765
Basic decimal arithmetic.

On the computer, divide the integer value by 10 million, using floating point division, to get the floating point value.

Conversely, multiply the floating point value by 10 million to get the integer value.
User avatar
By R34220
#236823
jremington wrote: Tue Nov 01, 2022 1:49 pm Basic decimal arithmetic.

On the computer, divide the integer value by 10 million, using floating point division, to get the floating point value.

Conversely, multiply the floating point value by 10 million to get the integer value.
Thanks!
 Topic permissions

You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum