我试图将我存储在数据库中的 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 复制)
关于android - 将 PlaceID 字符串转换为 LatLng 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54213872/