我正在开发一个应用程序,我需要检索当前位置附近的餐馆 . 论坛建议我使用Google Places API . 当我阅读Google Place API时,它说项目需要是一个“Google App Engine项目”的Android客户端 . 但我感到困惑的是,这是一种正确的做法,因为我对Google世界还不熟悉 .
有人可以建议我哪个是检索当前位置附近餐馆的最佳方式吗?
谢谢 .
点击此链接 . 为您的应用创建一个应用密钥,您只需要发出Http请求,您将获得Xml // json中的所有信息 . https://developers.google.com/places/documentation/
https://maps.googleapis.com/maps/api/place/search/xml?location=-33.8670522,151.1957362&radius=500&types=food&name=harbour&sensor=false&key=AddYourOwnKeyHere
在上面的网址中,添加你的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; } }
1 回答
点击此链接 . 为您的应用创建一个应用密钥,您只需要发出Http请求,您将获得Xml // json中的所有信息 . https://developers.google.com/places/documentation/
https://maps.googleapis.com/maps/api/place/search/xml?location=-33.8670522,151.1957362&radius=500&types=food&name=harbour&sensor=false&key=AddYourOwnKeyHere
在上面的网址中,添加你的Api密钥和locaton . 它会向你返回一个xml,其中包含500米圆圈内的所有restras .
此网址只接受获取请求 . Yov必须在Url中附加所有参数 .