【问题标题】:Android - How to get Google Places data using String address instead of the Place ID?Android - 如何使用字符串地址而不是地点 ID 获取 Google 地点数据?
【发布时间】:2017-08-22 05:33:38
【问题描述】:

有没有办法只使用给定的地址来获取 Google 地方信息(如经度、纬度、评级、姓名、电话号码等)?

因为我有一个很长的列表,就像一个很长的地址列表。我需要将该地址指向谷歌地图,为了让我这样做,我需要先从谷歌获取信息。

【问题讨论】:

标签: java android google-maps google-places-api


【解决方案1】:

您可以通过地址获取纬度和经度。你的代码。

public GeoPoint getLocationFromAddress(String strAddress){

Geocoder coder = new Geocoder(this);
List<Address> address;
GeoPoint p1 = null;

try {
    address = coder.getFromLocationName(strAddress,5);
    if (address==null) {
       return null;
    }
    Address location=address.get(0);
    location.getLatitude();
    location.getLongitude();

p1 = new GeoPoint((double) (location.getLatitude() * 1E6),
                  (double) (location.getLongitude() * 1E6));

return p1;
}
}

您必须将 Places 库添加到您的项目中。

compile 'com.google.android.gms:play-services-places:+.'

【讨论】:

  • 谢谢,它可以获取位置的坐标,但我仍然需要获取placeID。
【解决方案2】:

您可以使用 Android AutocompleteGeocoding Web Service API 来执行此操作

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多