简体   繁体   English

获取我当前位置的Google Places API(位置搜索)的名称

[英]Getting name of google places API (Place Search) for my current location

I am making an android app, in which I will use the name of current location to search its details over wikipedia. 我正在制作一个android应用程序,其中将使用当前位置的名称通过Wikipedia搜索其详细信息。 for eg If I am in Madame Tussauds, First I ll get the current location coordinates then after reverse geocoding, it's info will be searched over wikipedia and displayed in my app. 例如,如果我在杜莎夫人蜡像馆中,首先我将获得当前位置坐标,然后进行反向地理编码后,其信息将通过Wikipedia搜索并显示在我的应用中。

I have my current location coordinates but the problem is when I reverse geocode the coordinates, I don't get the place name. 我有当前的位置坐标,但是问题是当我对坐标进行地理编码时,我没有得到地名。 for eg for coordinates 33.651826, 73.156593 , when I reverse geocode, I get Park Road, Pakistan where as the name of the place is COMSATS Institute of Information Technology . 例如对于坐标33.651826、73.156593,当我反转地理编码时,我到达了巴基斯坦的Park Road,该地的名称是COMSATS信息技术学院

I get COMSATS Institute of Information Technology in Google Places API (Place Search) in Name node. 我在“名称”节点的Google Places API(地方搜索)中获得COMSATS信息技术学院的证书 So is there a way I can use Google Places API's name node for my current location name rather than any place search or other features? 那么,有什么方法可以使用Google Places API的名称节点作为当前位置名称,而不是任何位置搜索或其他功能?

Or is there any way I can get the place name using lat lon? 还是有什么方法可以使用lat lon获得地名?

The Places API for Android , introduced in Google Play services 7.0 , offers an API around getting the current place using PlaceDetectionApi.getCurrentPlace() . Google Play服务7.0中引入的Android版Places API ,提供了一个使用PlaceDetectionApi.getCurrentPlace()获取当前位置的API。 That method uses the user's current location and then returns a list of likely places for the user to be at. 该方法使用用户的当前位置,然后返回用户可能位于的位置的列表。 You can then use Place.getName() to retrieve the name of the location and display it to the user. 然后,您可以使用Place.getName()检索位置的名称并将其显示给用户。

If you want the user to pick a location from around them (rather than choosing the topmost result for them), you can use the Place Picker UI . 如果您希望用户从他们周围选择一个位置(而不是为他们选择最高的结果),则可以使用Place Picker UI

Define a GoogleApiClient object and then call this method 定义一个GoogleApiClient对象,然后调用此方法

private void guessCurrentPlace() {
PendingResult<PlaceLikelihoodBuffer> result = Places.PlaceDetectionApi.getCurrentPlace( mGoogleApiClient, null );
result.setResultCallback( new ResultCallback<PlaceLikelihoodBuffer>() {
    @Override
    public void onResult( PlaceLikelihoodBuffer likelyPlaces ) {

        PlaceLikelihood placeLikelihood = likelyPlaces.get( 0 );
        String content = "";
        if( placeLikelihood != null && placeLikelihood.getPlace() != null && !TextUtils.isEmpty( placeLikelihood.getPlace().getName() ) )
            content = "Most likely place: " + placeLikelihood.getPlace().getName() + "\n";
        if( placeLikelihood != null )
            content += "Percent change of being there: " + (int) ( placeLikelihood.getLikelihood() * 100 ) + "%";
        mTextView.setText( content );

        likelyPlaces.release();
    }
});
}

Reference: http://code.tutsplus.com/articles/google-play-services-using-the-places-api--cms-23715 参考: http : //code.tutsplus.com/articles/google-play-services-using-the-places-api--cms-23715

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

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