将 PlaceID 字符串转换为 LatLng 对象
Converting a PlaceID string to LatLng object
我正在尝试将我存储在数据库中的 placeId 字符串转换为 LatLng 坐标,我得到了这样的 ID:place.getId()
来自一个地点对象,现在当我从服务器上取回它时,我想要将其转换回坐标或至少一个 Place 对象。
谢谢!
将对象声明为
GoogleApiClient mGoogleApiClient;
然后初始化为
mGoogleApiClient =
new GoogleApiClient.Builder(...)
...
.build();
并将其传递给 Places API 的函数。
Places.GeoDataApi.getPlaceById(mGoogleApiClient, placeId)
.setResultCallback(new ResultCallback<PlaceBuffer>() {
@Override
public void onResult(PlaceBuffer places) {
if (places.getStatus().isSuccess()) {
final Place myPlace = places.get(0);
LatLng queriedLocation = myPlace.getLatLng();
Log.v("Latitude is", "" + queriedLocation.latitude);
Log.v("Longitude is", "" + queriedLocation.longitude);
}
places.release();
}
});
并在回调中检索坐标。 (代码复制自 here)
我正在尝试将我存储在数据库中的 placeId 字符串转换为 LatLng 坐标,我得到了这样的 ID:place.getId()
来自一个地点对象,现在当我从服务器上取回它时,我想要将其转换回坐标或至少一个 Place 对象。
谢谢!
将对象声明为
GoogleApiClient mGoogleApiClient;
然后初始化为
mGoogleApiClient =
new GoogleApiClient.Builder(...)
...
.build();
并将其传递给 Places API 的函数。
Places.GeoDataApi.getPlaceById(mGoogleApiClient, placeId)
.setResultCallback(new ResultCallback<PlaceBuffer>() {
@Override
public void onResult(PlaceBuffer places) {
if (places.getStatus().isSuccess()) {
final Place myPlace = places.get(0);
LatLng queriedLocation = myPlace.getLatLng();
Log.v("Latitude is", "" + queriedLocation.latitude);
Log.v("Longitude is", "" + queriedLocation.longitude);
}
places.release();
}
});
并在回调中检索坐标。 (代码复制自 here)