从自动完成的位置api返回的place_id中获取Lat Lang [英] get Lat Lang from a place_id returned by autocomplete place api

本文介绍了从自动完成的位置api返回的place_id中获取Lat Lang的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用google自动完成位置api在我的应用程序中搜索该位置,现在我想获取所搜索位置的纬度和经度.如何从android中Google的自动完成位置api返回的结果中获取经度和纬度?

I am searching the place in my apps using the google autocomplete place api and now I want to get latitude and longitude of the place that i have searched. How to get latitude and longitude from the result returned by autocomplete place api by google in android?

推荐答案

以下使用针对Android的Google Places API的代码段为我工作了

The following code snippet which uses Google Places API for android worked for me

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();
  }
});

访问 Android版Google Places API ,以获取检索方法的完整列表来自某个地方的数据

Visit Google Places API for Android for a full list of methods to retrieve data from a place

这篇关于从自动完成的位置api返回的place_id中获取Lat Lang的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆