admin管理员组文章数量:1287505
I want to retrieve the full formatted address via Google Maps API v3 Reverse Geocoding, since it only shows the postal code and/or city and country in many (maybe all) countries. I want to also retrieve the street name and the other stuff you can get through the Reverse Geocoding (Address Lookup) function. But since I can't get data from XML files or addresses that are linked to an XML file in JavaScript, I must use the Reverse Geocoding function.
Reverse Geocoding (Address Lookup) shows 791 Long Ridge Lane, Gainesboro, Tennessee 38562, USA
and Reverse Geocoding shows Gainesboro, Tennessee 38562, USA
.
Is it possible to get the full formatted address even through Reverse Geocoding, or do I have to use the PHP XML file through Reverse Geocoding (Address Lookup)?
function coordinates_to_address(lat, lng) {
var latlng = new google.maps.LatLng(lat, lng);
geocoder.geocode({'latLng': latlng}, function(results, status) {
if(status == google.maps.GeocoderStatus.OK) {
if(results[1]) {
$('#address_current').text(results[1].formatted_address);
} else {
alert('No results found');
}
} else {
var error = {
'ZERO_RESULTS': 'Kunde inte hitta adress'
}
// alert('Geocoder failed due to: ' + status);
$('#address_new').html('<span class="color-red">' + error[status] + '</span>');
}
});
}
I want to retrieve the full formatted address via Google Maps API v3 Reverse Geocoding, since it only shows the postal code and/or city and country in many (maybe all) countries. I want to also retrieve the street name and the other stuff you can get through the Reverse Geocoding (Address Lookup) function. But since I can't get data from XML files or addresses that are linked to an XML file in JavaScript, I must use the Reverse Geocoding function.
Reverse Geocoding (Address Lookup) shows 791 Long Ridge Lane, Gainesboro, Tennessee 38562, USA
and Reverse Geocoding shows Gainesboro, Tennessee 38562, USA
.
Is it possible to get the full formatted address even through Reverse Geocoding, or do I have to use the PHP XML file through Reverse Geocoding (Address Lookup)?
function coordinates_to_address(lat, lng) {
var latlng = new google.maps.LatLng(lat, lng);
geocoder.geocode({'latLng': latlng}, function(results, status) {
if(status == google.maps.GeocoderStatus.OK) {
if(results[1]) {
$('#address_current').text(results[1].formatted_address);
} else {
alert('No results found');
}
} else {
var error = {
'ZERO_RESULTS': 'Kunde inte hitta adress'
}
// alert('Geocoder failed due to: ' + status);
$('#address_new').html('<span class="color-red">' + error[status] + '</span>');
}
});
}
Share
Improve this question
edited Oct 15, 2014 at 16:57
Airikr
asked Oct 15, 2014 at 16:40
AirikrAirikr
6,43615 gold badges64 silver badges112 bronze badges
0
1 Answer
Reset to default 10To get the most precise result, use the first result (results[0]
), not the second (results[1]
):
function coordinates_to_address(lat, lng) {
var latlng = new google.maps.LatLng(lat, lng);
geocoder.geocode({'latLng': latlng}, function(results, status) {
if(status == google.maps.GeocoderStatus.OK) {
if(results[0]) {
$('#address_current').text(results[0].formatted_address);
} else {
alert('No results found');
}
} else {
var error = {
'ZERO_RESULTS': 'Kunde inte hitta adress'
}
// alert('Geocoder failed due to: ' + status);
$('#address_new').html('<span class="color-red">' + error[status] + '</span>');
}
});
}
本文标签: javascriptGet the full formatted address from Reverse GeocodingStack Overflow
版权声明:本文标题:javascript - Get the full formatted address from Reverse Geocoding - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741288354a2370404.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论