获取我当前位置的 google 个地点的名称 API(地点搜索)
Getting name of google places API (Place Search) for my current location
我正在制作一个 android 应用程序,我将在其中使用当前位置的名称在维基百科上搜索其详细信息。例如如果我在杜莎夫人蜡像馆,首先我会得到当前的位置坐标,然后在反向地理编码后,它的信息将在维基百科上搜索并显示在我的应用程序中。
我有我当前的位置坐标,但问题是当我对坐标进行反向地理编码时,我没有得到地名。例如对于坐标 33.651826、73.156593,当我反向地理编码时,我得到 Park Road, Pakistan,因为这个地方的名称是 COMSATS 信息技术研究所。
我在 COMSATS Institute of Information Technology in Google Places API (Place Search) 名称节点。那么有没有一种方法可以将 Google Places API 的名称节点用于我当前的位置名称而不是任何地点搜索或其他功能?
或者有什么方法可以使用经纬度获取地名?
Places API for Android, introduced in Google Play services 7.0, offers an API around getting the current place using PlaceDetectionApi.getCurrentPlace(). 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() 检索位置名称并将其显示给用户。
如果您希望用户从他们周围选择一个位置(而不是为他们选择最上面的结果),您可以使用 Place Picker UI.
定义一个 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();
}
});
}
参考:http://code.tutsplus.com/articles/google-play-services-using-the-places-api--cms-23715
我正在制作一个 android 应用程序,我将在其中使用当前位置的名称在维基百科上搜索其详细信息。例如如果我在杜莎夫人蜡像馆,首先我会得到当前的位置坐标,然后在反向地理编码后,它的信息将在维基百科上搜索并显示在我的应用程序中。
我有我当前的位置坐标,但问题是当我对坐标进行反向地理编码时,我没有得到地名。例如对于坐标 33.651826、73.156593,当我反向地理编码时,我得到 Park Road, Pakistan,因为这个地方的名称是 COMSATS 信息技术研究所。
我在 COMSATS Institute of Information Technology in Google Places API (Place Search) 名称节点。那么有没有一种方法可以将 Google Places API 的名称节点用于我当前的位置名称而不是任何地点搜索或其他功能?
或者有什么方法可以使用经纬度获取地名?
Places API for Android, introduced in Google Play services 7.0, offers an API around getting the current place using PlaceDetectionApi.getCurrentPlace(). 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() 检索位置名称并将其显示给用户。
如果您希望用户从他们周围选择一个位置(而不是为他们选择最上面的结果),您可以使用 Place Picker UI.
定义一个 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();
}
});
}
参考:http://code.tutsplus.com/articles/google-play-services-using-the-places-api--cms-23715