admin管理员组文章数量:1391981
I am currently using the google maps api to geocode locations on the map and return the address of the street.
I currently return the address with the following code:
function codeLatLng(markerPos) {
geocoder.geocode({'latLng': markerPos}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (results[1]) {
//Set markerAddress variable
var markerAddress = results[0].formatted_address;
alert(markerAddress);
...
But what if I don't want to return the formatted address but a more detailed version using Address Component Types, how can I return certain address values like:
Help appreciated.
I am currently using the google maps api to geocode locations on the map and return the address of the street.
I currently return the address with the following code:
function codeLatLng(markerPos) {
geocoder.geocode({'latLng': markerPos}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (results[1]) {
//Set markerAddress variable
var markerAddress = results[0].formatted_address;
alert(markerAddress);
...
But what if I don't want to return the formatted address but a more detailed version using Address Component Types, how can I return certain address values like: http://code.google./apis/maps/documentation/geocoding/#Types
Help appreciated.
Share Improve this question edited Dec 24, 2013 at 16:55 Kara 6,22616 gold badges53 silver badges58 bronze badges asked Jan 20, 2012 at 13:26 hairynuggetshairynuggets 3,32122 gold badges57 silver badges90 bronze badges2 Answers
Reset to default 4May I ask, why are you checking for results[1]
and then using results[0]
(or is it just a typo I should ignore)?
As long as status
is OK
, there will be at least one result.
Otherwise, status
would be ZERO_RESULTS
.
Anyway, you can use something like this:
function codeLatLng(markerPos) {
geocoder.geocode({'latLng': markerPos}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var markerAddress = results[0].address_ponents[0].long_name
+ ' (type: ' + results[0].address_ponents[0].types[0] + ')';
alert(markerAddress);
You can play a lot with the whole address_ponents
array, have fun! :)
For even more fun, have a look at the (source code of the) Google Maps API v3 Geocoder Tool at http://gmaps-samples-v3.googlecode./svn/trunk/geocoder/v3-geocoder-tool.html
long_name
is the full text description or name of the address ponent as returned by the Geocoder.
function codeLatLng(markerPos) {
geocoder.geocode({'latLng': markerPos}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (results[1]) {
//Set markerAddress variable
var markerAddress = results[0].long_name;
alert(markerAddress);
...
本文标签: javascriptHow to return address types from google maps geocodeStack Overflow
版权声明:本文标题:javascript - How to return address types from google maps geocode? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744719582a2621613.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论