在Google Places API中传递当前位置(经度和纬度)



我正在尝试将Google Places API集成到我的应用程序中。现在我正在查找我的手机当前位置,如何将我获得的经度和纬度嵌入以下URL,而不是"location=34.052222,-118.242778"

"https://maps.googleapis.com/maps/api/place/search/xml?location=34.0522222,-118.242778&半径=500&types=餐馆&传感器=错误&key=Your_API_key"

你是说如何进行字符串操作,比如(未测试):

int latitude = ...;
int longitude = ...;
String preamble = "https://maps.googleapis.com/maps/api/place/search/xml?location=";
String postamble = "&radius=500&types=restaurants&sensor=true&key=";
String key = "Your_api_key";
String latStr = latitude + "";
String longStr = longitude + "";
String url = preamble + latStr + "," + longStr + postamble + key;
$lat = location[0];
$long = location[1];

应该可以,但我使用json从谷歌获取long和lat。更好。如果不起作用,我可以再检查一次。

这里有更好的json解决方案:

http://maps.googleapis.com/maps/api/geocode/json?address=Atlantis&传感器=真&oe=utf-8

您应该将亚特兰蒂斯号更改为

最新更新