如何提高 Google 地理编码器响应的精度?
Posted
技术标签:
【中文标题】如何提高 Google 地理编码器响应的精度?【英文标题】:How can I increase the precision of the Google Geocoder Response? 【发布时间】:2015-10-06 17:54:06 【问题描述】:我使用 Google Geocoder 编写了两个测试: 一项测试只是请求给定地址的地理点,
而第二个获取从谷歌检索的地理点并尝试获取地址。
我的问题是,在地址中谷歌返回给我的地址与它自己的(地理点)不一样! 总结一下; 我的地址:Hirtenstraße 4, 10178 Berlin, Germany
Google 的地理点:lat = 52.5257827,lng = 13.4113952
谷歌返回地址:Hirtenstraße 4, 10178 Berlin, 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】:结果是:
"location_type": "RANGE_INTERPOLATED"
所以它不会是精确的,它是插值的。您需要一个具有“ROOFTOP”结果的地理编码器结果,但 Google 的地理编码器(还没有)。
完整的地理编码器响应:
"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"
]
【讨论】:
以上是关于如何提高 Google 地理编码器响应的精度?的主要内容,如果未能解决你的问题,请参考以下文章