如何提高Google Geocoder响应的精确度?

时间:2015-10-06 17:54:06

标签: google-maps google-geocoder

我使用Google Geocoder编写了两个测试: 一个测试只是请求给定地址的地理输出,

而第二个从谷歌检索地理点并尝试获取地址。

我的问题是,在地址中google返回给我的是它自己的(geo points)是不一样的! 总结一下; 我的地址:Hirtenstraße4,10178Berlin,Germany

Google的地理位置:lat = 52.5257827,lng = 13.4113952

Google返回地址:Hirtenstraße4,10178Berlin,Germany

我的问题:有没有办法控制(提高)你回来的地理点结果的精确度?

// ####### example code below################################################
@Test
 public void testGetPoints() throws IOException {
    final Geocoder geocoder = new Geocoder();

    String land = "Germany";
    String city = "Berlin";
    String streetAddress = "4 Hirtenstraße";
    String postcode = "10178";

    String fullAddress = streetAddress + ",+" + postcode + ",+" + city + ",+" + land;
    fullAddress = fullAddress.replace(" ", "+");

    GeocoderRequest geocoderRequest = new GeocoderRequestBuilder().setAddress(fullAddress).setLanguage("en").getGeocoderRequest();
    GeocodeResponse geocoderResponse = geocoder.geocode(geocoderRequest);
    ArrayList<GeocoderResult> addresses = new ArrayList<>(geocoderResponse.getResults());

    for (GeocoderResult r : addresses) {
        System.out.println(r.getGeometry().getLocation());
    }
}


@Test
public void testGeocoder() throws IOException {
    ArrayList<GeocoderResult> addresses = new ArrayList<GeocoderResult>();
    GeocodeResponse geocoderResponse;
    Geocoder geocoder = new Geocoder();

    // geo points we get from the previous test
    BigDecimal lat = new BigDecimal(52.5257827);
    BigDecimal lng = new BigDecimal(13.4113952);

    GeocoderRequest geocoderRequest = new GeocoderRequestBuilder().setLocation(new LatLng(lat, lng)).setLanguage("en").getGeocoderRequest();

    geocoderResponse = geocoder.geocode(geocoderRequest);
    addresses.addAll(geocoderResponse.getResults());

    for (GeocoderResult r : addresses) {
        System.out.println(r.getFormattedAddress());
        // first value returns:
        // Hirtenstraße 5, 10178 Berlin, Germany !!!!!  not 4!
    }
}

1 个答案:

答案 0 :(得分:0)

结果是:

"location_type": "RANGE_INTERPOLATED"

因此它不会精确,它是插值的。您需要一个具有&#34; ROOFTOP&#34;的地理编码器结果。结果,但谷歌的地理编码器还没有(但)。

完整的地理编码器响应:

{
  "address_components": [
    {
      "long_name": "4",
      "short_name": "4",
      "types": [
        "street_number"
      ]
    },
    {
      "long_name": "Hirtenstraße",
      "short_name": "Hirtenstraße",
      "types": [
        "route"
      ]
    },
    {
      "long_name": "Mitte",
      "short_name": "Mitte",
      "types": [
        "sublocality_level_1",
        "sublocality",
        "political"
      ]
    },
    {
      "long_name": "Berlin",
      "short_name": "Berlin",
      "types": [
        "locality",
        "political"
      ]
    },
    {
      "long_name": "Berlin",
      "short_name": "Berlin",
      "types": [
        "administrative_area_level_1",
        "political"
      ]
    },
    {
      "long_name": "Germany",
      "short_name": "DE",
      "types": [
        "country",
        "political"
      ]
    },
    {
      "long_name": "10178",
      "short_name": "10178",
      "types": [
        "postal_code"
      ]
    }
  ],
  "formatted_address": "Hirtenstraße 4, 10178 Berlin, Germany",
  "geometry": {
    "bounds": {
      "Ka": {
        "H": 52.5257728,
        "j": 52.5257827
      },
      "Ga": {
        "j": 13.41138669999998,
        "H": 13.411395200000015
      }
    },
    "location": {
      "H": 52.5257827,
      "L": 13.411395200000015
    },
    "location_type": "RANGE_INTERPOLATED",
    "viewport": {
      "Ka": {
        "H": 52.5244287697085,
        "j": 52.5271267302915
      },
      "Ga": {
        "j": 13.410041969708459,
        "H": 13.412739930291536
      }
    }
  },
  "partial_match": true,
  "place_id": "EipIaXJ0ZW5zdHJhw59lIDQsIDEwMTc4IEJlcmxpbiwgRGV1dHNjaGxhbmQ",
  "types": [
    "street_address"
  ]
}