简体   繁体   English

检索当前位置的附近地点

[英]Retrieve nearby places of a current location

I am working on an application where I need to retrieve nearby restaurants of a current location. 我正在开发一个需要检索当前位置附近餐厅的应用程序。 Forums suggested me to use Google Places API. 论坛建议我使用Google Places API。 When I read about Google Place API, it says that a project needs to be a "Google App Engine project" + Android client. 当我阅读Google Place API时,它说一个项目必须是“ Google App Engine项目” + Android客户端。 But I got confused that will that be a right way of doing it as I am fairly new to Google world. 但是我感到困惑,因为我对Google世界还很陌生,那将是正确的做法。

Can someone suggest me which will be the best way of retrieving nearby restaurants of a current location? 有人可以建议我,这是检索当前位置附近餐厅的最佳方法吗?

Thanks. 谢谢。

follow this link. 点击此链接。 Create an app key for your app & You only have to make an Http request, & you will get all info in Xml//json. 为您的应用程序创建一个应用程序密钥,您只需要发出Http请求,您就可以在Xml // json中获取所有信息。 https://developers.google.com/places/documentation/ 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 https://maps.googleapis.com/maps/api/place/search/xml?location=-33.8670522,151.1957362&radius=500&types=food&name=harbour&sensor=false&key=AddYourOwnKeyHere

In above url, Add your Api key & locaton. 在上面的网址中,添加您的Api密钥和位置。 It will return a xml to you containing all restras in circle of 500m. 它将向您返回一个xml,其中包含500m范围内的所有restras。

this url will only accept get Requests. 该网址仅接受get请求。 Yov will have to append all parameters in Url itself. 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;
    }

}

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

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