简体   繁体   English

如何克服Google静态地图API 6小数位精度限制?

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

Google Static Maps API Documentation states: Google Static Maps API文档指出:

Latitudes and longitudes are defined using numerals within a comma-separated text string that have a precision to 6 decimal places. 纬度和经度是使用逗号分隔的文本字符串中的数字定义的,这些数字的精度为小数点后6位。 For example, "40.714728,-73.998672" is a valid geocode value. 例如,“ 40.714728,-73.998672”是有效的地理编码值。 Precision beyond the 6 decimal places is ignored. 超过6位小数的精度将被忽略。

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) 编辑 :实际上,小数点后6位允许大约2厘米的精度,如323go注释 。有关更多信息,请参见底部的编辑。)

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: 例如:尝试在埃菲尔铁塔上放置标记( Lat: 48.8583701,Lon: 2.2922926 )会被截断(对Lat: 48.858370, Lon:2.292292 ),结果如下,其偏移量不可忽略:

在此处输入图片说明

I use static maps is because in my application I show multiple maps simultaneously inside the items of a RecyclerView . 我使用静态地图是因为在我的应用程序中,我同时在RecyclerView的项内显示多个地图。

I currently achieve that by asynchronously injecting the images returned by the Google static maps API via Picasso . 目前,我是通过Picasso异步注入Google静态地图API返回的图像来实现的。

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 作为一种解决方法,我正在考虑在精简模式下使用标准MapView ,但是我担心这可能会导致性能问题,如本问题所述

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 . 加载https://google.com/maps/place/Tour+Eiffel后 ,我使用的是URL中显示的坐标,在我的情况下,该坐标为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. 当网络版Google Maps的左侧面板处于打开状态(这是默认行为)时,图钉似乎位于地图的中心。

Nevertheless, the coordinates of the URL represent the center of the map including the part under the left panel . 不过, URL的坐标表示地图的中心,包括左侧面板下的部分 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 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: 那应该给您带来更好的结果,还请记住,您可以使用Geocoder放置带有地点名称或完整地址的标记,即:

Champ de Mars, 5 Avenue Anatole France, 75007 Paris, France 战神广场(Champ de Mars),法国阿纳托莱大街5号,邮政编码75007,法国巴黎

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();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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