我使用谷歌地图API,到目前为止我只使用formatted_address输出我的地理编码功能的结果。我如何修改我的功能才能获得只有街道的名称和数字?我想将它们插入到输入字段中。
我目前的功能如下:
function getAndDisplayNewAddress(position) {
var geocoder = new google.maps.Geocoder();
// Find out longitude and latitude
geocoder.geocode({
'latLng' : position
}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
$('#display_of_street').val(results[0].formatted_address);
}
});
}; // /function getAndDisplayStreet()
答案 0 :(得分:-1)
:)结果是您可以在此网站上关注的对象:)
在这里你可以看到它:http://jsfiddle.net/HoangHieu/x8dSP/3631/
function reverseGeocodeResult(results, status) {
currentReverseGeocodeResponse = results;
if (status == 'OK') {
if (results.length == 0) {
$('#id of element').val(results[0].formatted_address);
}
}
喜欢
{
"address_components": [{
"long_name": "192",
"short_name": "192",
"types": ["street_number"]
}, {
"long_name": "An Dương Vương",
"short_name": "An Dương Vương",
"types": ["route"]
}, {
"long_name": "phường 3",
"short_name": "phường 3",
"types": ["sublocality_level_1", "sublocality", "political"]
}, {
"long_name": "Ho Chi Minh City",
"short_name": "Ho Chi Minh City",
"types": ["locality", "political"]
}, {
"long_name": "Quận 5",
"short_name": "Quận 5",
"types": ["administrative_area_level_2", "political"]
}, {
"long_name": "Hồ Chí Minh",
"short_name": "Hồ Chí Minh",
"types": ["administrative_area_level_1", "political"]
}, {
"long_name": "Vietnam",
"short_name": "VN",
"types": ["country", "political"]
}],
"formatted_address": "192 An Dương Vương, phường 3, Quận 5, Hồ Chí Minh, Vietnam",
"geometry": {
"bounds": {
"xa": {
"k": 10.7576423,
"j": 10.7576594
},
"pa": {
"j": 106.6744804,
"k": 106.67448660000002
}
},
"location": {
"k": 10.7576423,
"B": 106.67448660000002
},
"location_type": "RANGE_INTERPOLATED",
"viewport": {
"xa": {
"k": 10.7563018697085,
"j": 10.7589998302915
},
"pa": {
"j": 106.67313451970847,
"k": 106.67583248029155
}
}
},
"types": ["street_address"]
}