Google Maps Address Components地理编码与Places API-短名称与长名称 [英] Google Maps Address Components Geocoding vs Places API - Short vs Long Name
问题描述
嘿,有GMaps API开发人员.首先-Google Maps/JS API v3是什么了不起的产品和服务-非常感谢!现在,有了一点点诚挚的谢意……
Hey there GMaps API developers. To start - what an incredible product and service the Google Maps/JS API v3 is - thank you so much! Now, with that important bit of sincere gratitude out of the way...
地址组件的short_name
与long_name
选项是一个不错的功能,但是对于每项服务,这两个属性大多包含相同的值,除了地理编码具有我对short_name
的期望,而场所具有的期望我期望两者都使用long_name
! *眼泪*
The short_name
vs long_name
options for address components is a nice feature, but for each service these two attributes mostly contain the same values, except geocode has what I would expect for short_name
for both and places has what I would expect for long_name
for both! *tears*
在Places库问世之前,我只是假设Google实际上没有街道名称,地区等的短/长版本-但是现在看来您愿意在某处使用这种格式-可能有所不同产品团队有不同的数据库?
Before Places library came out I just assumed that Google didn't actually have short/long versions for street name, localities, etc - but now it seems you do have that formatting somewhere - maybe different product teams have different databases?
那是怎么回事?
我正在谈论的图像(会嵌入,但这是我的第一个stackoverflow问题,因此没有声誉): http://i.imgur.com/XPVj8.png
Image of what I'm talking about (would embed but this is my first stackoverflow question so no reputation): http://i.imgur.com/XPVj8.png
我希望的工作方式的详细列表:
Detailed list of how I wish this worked:
- 对于路线,地理编码的
short_name
地方的long_name
- 在地理编码和地点之间的位置/子位置具有相同的类型"值(两者都可以,只需选择一个即可)
- 始终提供状态的长/短状态(administrative_area_level_1)-地理编码可以正确使用此状态,但是位置不可以
- 与国家/地区相同-地理编码的格式地址中的美国"在哪里? 如果
- 会很整洁,但是我想从数据的角度来看,这将是一个巨大的尝试
postal_code
long_name
具有zip + 4,- for routes, geocode's
short_name
places'long_name
- have the same "types" value for locality/sublocality between geocode and places (either is fine, just pick one)
- consistently provide short/long for state (administrative_area_level_1) - geocode gets this right but places doesn't
- same for country - and where is geocode getting its "USA" in the formatted address?
- would be neat if
postal_code
long_name
had zip+4, but I would imagine that'd be a huge endeavor from a data standpoint
非常感谢-期待对此行为有任何见识!
Thanks so much - looking forward to any insight on this behavior!
图片后面的代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>GMaps API V3 Geocoder vs Places Address Components | Short vs Long Name</title>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?sensor=true&libraries=places"></script>
<style type="text/css">
#map {height: 100px; width: 600px; border: 1px solid #333; margin-top: 0.6em; }
table { border-collapse: collapse; border-spacing: 0; }
table td {border-top: 1px solid #DDD; padding:4px 8px; }
</style>
<script type="text/javascript">
var map, geocoder, places, geocode_components, geocode_formatted, places_components, places_formatted
function initialize() {
geocoder = new google.maps.Geocoder();
geocoder.geocode({'address': '3 South Main Street, York New Salem, PA'},
function (results, status) {
geocode_components = results[0].address_components;
geocode_formatted = results[0].formatted_address;
map = new google.maps.Map(document.getElementById('map'), {
mapTypeId: google.maps.MapTypeId.ROADMAP,
center: results[0].geometry.location,
zoom: 10
});
places = new google.maps.places.PlacesService(map);
places.search({location: results[0].geometry.location, radius:100, keyword: "Pizza"},
function(results, status) {
//get details - this feels a little extraneous to me, but y'all know best
places.getDetails({reference: results[0].reference},
function(result, status) {
places_components = result.address_components;
places_formatted = result.formatted_address;
writeResults();
});
});
});
}
function writeResults() {
tbody = document.getElementById('results');
formatted = document.getElementById('formatted');
var rows = "";
for(var i=0; i<geocode_components.length; i++) {
var c = geocode_components[i];
rows = rows + '<tr><td>Geocoding</td><td>' + c.types[0] + '</td><td>' + c.short_name + '</td><td>' + c.long_name + '</td></tr>';
}
for(var i=0; i<places_components.length; i++) {
var c = places_components[i];
rows = rows + '<tr><td>Places</td><td>' + c.types[0] + '</td><td>' + c.short_name + '</td><td>' + c.long_name + '</td></tr>';
}
tbody.innerHTML = rows;
formatted.innerHTML = '<br />Geocode Formatted: ' + geocode_formatted + '<br />' + 'Places Formatted: ' + places_formatted;
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<div id="map"></div>
<table>
<thead><tr><th>Service</th><th>Type</th><th>Short Name</th><th>Long Name</th></tr></thead>
<tbody id="results"></tbody>
</table>
<div id="formatted"></div>
</body>
</html>
推荐答案
如注释中所述-该问题(请求)已于2013年1月修复/实施,请参见
As noted in comments - this question (request) was fixed/implemented back in January, 2013, see https://issuetracker.google.com/issues/35821543
这篇关于Google Maps Address Components地理编码与Places API-短名称与长名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!