Google Geocoding – 抓取地址和坐标

所以这就是我所追求的,我被告知这不可能,但我现在还不会放弃!

假设用户在“伦敦”中输入我的位置搜索框并点击“地理编码”我能够得到该位置的坐标,就像这个例子:

http://gmaps-samples-v3.googlecode.com/svn/trunk/geocoder/v3-geocoder-tool.html

但是我要说我有以下字段:

Town: City: Country: Long: Lat: 

是否可以通过此请求填写所有这些字段,而不仅仅是坐标? 例如,我将获得以下信息,然后我可以将其存储在cookie中:

 Town: - City: London Country: UK Long: 123.45 Lat: 123.45 

试试这个:

 function getLatLongDetail(latLng) { var geocoder = new google.maps.Geocoder(); geocoder.geocode({ 'latLng': latLng }, function (results, status) { if (status == google.maps.GeocoderStatus.OK) { if (results[0]) { var address = "", city = "", state = "", zip = "", country = ""; for (var i = 0; i < results[0].address_components.length; i++) { var addr = results[0].address_components[i]; // check if this entry in address_components has a type of country if (addr.types[0] == 'country') country = addr.long_name; else if (addr.types[0] == 'street_address') // address 1 address = address + addr.long_name; else if (addr.types[0] == 'establishment') address = address + addr.long_name; else if (addr.types[0] == 'route') // address 2 address = address + addr.long_name; else if (addr.types[0] == 'postal_code') // Zip zip = addr.short_name; else if (addr.types[0] == ['administrative_area_level_1']) // State state = addr.long_name; else if (addr.types[0] == ['locality']) // City city = addr.long_name; } alert('City: '+ city + '\n' + 'State: '+ state + '\n' + 'Zip: '+ zip + '\n' + 'Country: ' + country); } } }); } 

编辑:

示例就在这里 。