简体   繁体   中英

How to overcome google static maps API 6 decimal places precision limit?

Google Static Maps API Documentation states:

Latitudes and longitudes are defined using numerals within a comma-separated text string that have a precision to 6 decimal places. For example, "40.714728,-73.998672" is a valid geocode value. Precision beyond the 6 decimal places is ignored.

However, I have noted that in many cases, that precision is not enough. ( Edit : Actually, 6 decimal places allows a precision of approximately 2 cms, as 323go comments . See the edit at the bottom for further info)

Eg: Trying to put a marker on the Eiffel Tower ( Lat: 48.8583701,Lon: 2.2922926 ) gets truncated (to Lat: 48.858370, Lon:2.292292 ) obtaining the following result, which has a non negligible offset:

在此处输入图片说明

I use static maps is because in my application I show multiple maps simultaneously inside the items of a RecyclerView .

I currently achieve that by asynchronously injecting the images returned by the Google static maps API via Picasso .

This current approach works well and performs smoothly, the only problem being the lack of precision of the map.

As a workaround, I am considering using the standard MapView in Lite Mode , but I am concerned that it could lead to performance issues, as stated in this question

Is there a way to overcome that limit, even if it requires paying?



Edit

I was using wrong coordinates. I'll explain how I got them, just in case anyone else makes the same mistake.

I was using the coordinates that appear in the URL after loading https://google.com/maps/place/Tour+Eiffel , which in my case is this URL .

When the left side panel of the web version of Google Maps is open (which is the default behaviour), the pin appears to be in the center of the map.

Nevertheless, the coordinates of the URL represent the center of the map including the part under the left panel . This is easy to notice once the left panel is collapsed.

This is what caused the horizontal offset.

Im trying to figure this out but on my side everything is working fine and precise, i noticed you are using different coordinates than mine

For the Eiffel Tower i used:

48.858285, 2.294388

That should give you a better result, also remember you can place a marker with the name of the place or with the full address with Geocoder which is:

Champ de Mars, 5 Avenue Anatole France, 75007 Paris, France

Something like this should help

Geocoder geocoder = new Geocoder(<your context>);  
List<Address> addresses;
addresses = geocoder.getFromLocationName(<String address>, 1);
if(addresses.size() > 0) {
    double latitude= addresses.get(0).getLatitude();
    double longitude= addresses.get(0).getLongitude();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM