gpt4 book ai didi

Android convert CID location to Coordinates(Android将CID位置转换为坐标)

转载 作者:bug小助手 更新时间:2023-10-24 17:55:17 31 4
gpt4 key购买 nike



I built an android app which can handle a share intent from Google Maps and show it's coordinates.

我构建了一个Android应用程序,它可以处理来自谷歌地图的共享意图,并显示它的坐标。



The problem is that they send a short url which I decode with Google's url shortner api and in some cases, the result long link is of this type: http://maps.google.com/?cid=3635533832900933072&hl=en&gl=us.

问题是他们发送了一个短URL,我用谷歌的URL Shorner API对其进行了解码,在某些情况下,结果长链接是这样的:http://maps.google.com/?cid=3635533832900933072&hl=en&gl=us.



Can anyone help me on how to get the coresponding coordinates to "cid=3635533832900933072"

有没有人能帮我弄到“Cid=3635533832900933072”的对应坐标?


更多回答
优秀答案推荐

As far as I know there is no public API to get the location from a cid.

据我所知,目前还没有从CID获取位置的公共API。



However, a possible workaround would be to parse the Google Maps output to obtain the latitude and longitude (though it may be brittle, if they change the result format).

然而,一种可能的解决方法是解析Google Maps输出以获得纬度和经度(尽管如果它们改变结果格式,它可能很脆弱)。



(Although the url contains output=json, it's not actually json -- that's why I parse it with substring() and such instead of using JSONObject).

(虽然url包含out=json,但它实际上并不是json--这就是为什么我使用substring()之类而不是使用JSONObject来解析它)。



Try this code:

试试这个代码:



public static LatLng getCidCoordinates(String cid)
{
final String URL_FORMAT = "http://maps.google.com/maps?cid=%s&q=a&output=json";
final String LATLNG_BEFORE = "viewport:{center:{";
final String LATLNG_AFTER = "}";
final String LATLNG_SEPARATOR = ",";
final String LAT_PREFIX = "lat:";
final String LNG_PREFIX = "lng:";

try
{
HttpClient client = new DefaultHttpClient();
HttpGet get = new HttpGet(String.format(URL_FORMAT, cid));
HttpResponse response = client.execute(get);

String text = EntityUtils.toString(response.getEntity(), "UTF-8");

int startIndex = text.indexOf(LATLNG_BEFORE);
if (startIndex == -1)
return null;

startIndex += LATLNG_BEFORE.length();
int endIndex = text.indexOf(LATLNG_AFTER, startIndex);

// Should be "lat:<number>,lng:<number>"
String[] parts = text.substring(startIndex, endIndex).split(LATLNG_SEPARATOR);
if (parts.length != 2)
return null;

if (parts[0].startsWith(LAT_PREFIX))
parts[0] = parts[0].substring(LAT_PREFIX.length());
else
return null;

if (parts[1].startsWith(LNG_PREFIX))
parts[1] = parts[1].substring(LNG_PREFIX.length());
else
return null;

return new LatLng(Double.parseDouble(parts[0]), Double.parseDouble(parts[1]));
}
catch (NumberFormatException e)
{
e.printStackTrace();
return null;
}
catch (IOException e)
{
e.printStackTrace();
return null;
}
}


After reading this post yesterday, I found a new method to do it. I hope Google do not close this new API and hidden parameter. :)

昨天读了这篇文章后,我发现了一种新的方法来做这件事。我希望Google不要关闭这个新的API和隐藏参数。:)



You can use this API hidden parameter to get the coordinater. Usage: https://maps.googleapis.com/maps/api/place/details/json?cid=YOUR_CID&key=YOUR_KEY

您可以使用此API隐藏参数来获取协调器。用法:https://maps.googleapis.com/maps/api/place/details/json?cid=YOUR_CID&key=YOUR_KEY



It returns a result contains formatted address, place_id, name of the address and GPS coordinater.

它返回一个结果,其中包含格式化的地址、Place_id、地址名称和GPS协调员。



Please see my blog to see more detail: https://leonbbs.blogspot.com/2018/03/google-map-cid-to-placeid-or-get.html

请查看我的博客以了解更多细节:https://leonbbs.blogspot.com/2018/03/google-map-cid-to-placeid-or-get.html



In latest Google Maps update, the share intent contains the address name in the body which can be decoded with Geocoder into coordinates.

在最新的谷歌地图更新中,共享意向在正文中包含了地址名称,可以用地理编码器将其解码为坐标。




  1. Send request to the link

  2. Retrieve response and parse body

  3. Extract meta-info with the Place name

  4. Place name can be used to find location by Geocoder


For example:

例如:



<meta content="Big Ben · London SW1A 0AA, United Kingdom" itemprop="name">
<meta content="Big Ben · London SW1A 0AA, United Kingdom" property="og:title">
<meta content="Big Ben · London SW1A 0AA, United Kingdom" property="og:site_name">

Obtain Place location by Google Maps CID gist:

根据谷歌地图CID获取地点位置:


https://gist.github.com/asilichenko/b0000eb1562c9e4e75b0d43d799260bc

Https://gist.github.com/asilichenko/b0000eb1562c9e4e75b0d43d799260bc


更多回答

@Richard Yes, why? Is it broken?

@理查德是的,怎么了?它坏了吗?

@matiash Well, when I try to search details about a public transportation stop, JSON returns empty. :[

@Matiash嗯,当我尝试搜索有关公共交通站点的详细信息时,JSON返回空。:[

It seems that maps.google.com/maps?cid=%s&q=a&output=json is not working any more. Any other ideas on how to get the coordinates from cid?

似乎maps.google.com/maps.google.com&maps.google.com/maps.google.cd=%S&q=a&out=json不再工作。关于如何从CID获取坐标还有其他想法吗?

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com