我正在处理需要检索当前位置的附近餐馆的应用程序。论坛建议我使用Google Places API。 当我阅读Google Place API时,它说项目需要成为“Google App Engine项目”+ Android客户端。但我感到困惑,这将是一个正确的方式,因为我对Google世界相当陌生。检索当前位置的附近地点
有人可以建议我这将是检索当前位置的附近餐馆的最佳方式吗?
谢谢。
我正在处理需要检索当前位置的附近餐馆的应用程序。论坛建议我使用Google Places API。 当我阅读Google Place API时,它说项目需要成为“Google App Engine项目”+ Android客户端。但我感到困惑,这将是一个正确的方式,因为我对Google世界相当陌生。检索当前位置的附近地点
有人可以建议我这将是检索当前位置的附近餐馆的最佳方式吗?
谢谢。
点击此链接。 为您的应用程序创建应用程序密钥&您只需提出Http请求,&您将获得Xml // json中的所有信息。 https://developers.google.com/places/documentation/
在上述网址,添加您的API密钥& locaton。它会返回一个xml给你,包含所有500米的圆圈里的所有restras。
此网址只接受取得请求。 Yov必须在Url本身中追加所有参数。
@Override
public void run()
{
String params="location="+(location.getLatitude())+","+(location.getLongitude())+"&radius=5000&types=food&sensor=false&key=your kay";
try
{
http.getPlaces(new URL("https://maps.googleapis.com/maps/api/place/search/xml?"+params));
Log.i("url", "https://maps.googleapis.com/maps/api/place/search/xml?"+params);
setList();
}
catch (MalformedURLException e)
{
e.printStackTrace();
}
catch (Exception e)
{
e.printStackTrace();
}
}
});
public void getPlacesDetails(URL url) throws Exception {
try
{
connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setUseCaches(false);
connection.setConnectTimeout(TIMEOUT_CONNECT_MILLIS);
connection.setReadTimeout(TIMEOUT_READ_MILLIS);
connection.setRequestMethod("GET");
inStream = (InputStream) connection.getInputStream();
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
XMLReader xr = sp.getXMLReader();
HospitalDetailParser myXMLHandler = new HospitalDetailParser();
xr.setContentHandler(myXMLHandler);
xr.parse(new InputSource(inStream));
}
catch (MalformedURLException e)
{
Log.i("exception in sms", "" + e.toString());
throw e;
}
catch (Exception e)
{
Log.i("exception in sms", "" + e.toString());
throw e;
}
}
也有一个“入门”指南到API的地方在:https://developers.google.com/academy/apis/maps/places/ – saxman 2012-07-18 22:45:53
在使用谷歌API的地方,我得到一个“ VerifyError“在运行时。 LogCat说 - “无法找到GenericUrl类”,但编译显示没有这样的错误。我在论坛上搜索并实施所有建议的解决方案,但仍然得到相同的错误...我错过了什么? – 2012-07-19 06:43:45
你能提供相关的代码和日志吗? 我已编辑答案。请检查。 – Kamal 2012-07-19 09:34:54