api - Return data using a marker in Google Maps v3 -
Is it possible that street address, province, zip code (postal code) by using a marker in Google Maps, Come back to the city and country? V3?
Sometimes data is not returned using formatted_address.
Is there any way I can do something special? Such as return [1]. Whistle, returns [1]. Country, Returns [1]. Address ...
Yes. I wrote a function that reads the components of geographic results.
Here is a complete example
Doctype html & gt; & Lt; Html & gt; & Lt; Top & gt; & Lt; Style & gt; # Map-canvas {width: 500px; Height: 400 pixels; } & Lt; / Style & gt; & Lt; Script type = "text / javascript" src = "http://maps.googleapis.com/maps/api/js?sensor=false" & gt; & Lt; / Script & gt; & Lt; Script & gt; Function init () {var center = new google.maps.LatLng (50.845464, 4.3571121); // Brussels classocoder; Geocodar = new google.maps.Geocoder (); Var map = new google.maps.Map (document.getElementById ('map-canvas'), {center: center, zoom: 15, map type id: google.maps.MapTypeId.ROADMAP}); Var marker = new google.maps.marker ({draggable: true, title: "drag to see the components I know", map: map, position: center}); Google.maps.event.addListener (marker, 'dragend', function (e) {document.getElementById ('display') innerHTML = ''; .up position = marker.getPosition (); // geoposition geocoder.geocode find ( {LatLng: Status}, Function (responses) {if (responses & amp; responses.length & gt; 0) {// postal_code = addresComponent received in postcode ('postal_code', reactions [0]) if (Postal_code) {document.getElementById ('display') innerHTML + = '& lt; div & gt; Postal code:'. + Postal_code + '& lt; / div & gt;';} // road on road obtained = AddresComponent ('routing', reactions [0]) (street) {document.getElementById ('display'). InnerHTML + '' (Street_number ', responses [0]) if (street_number) {docum Ent:' street + '& lt; / div & gt;';} // street number (number of house in road) var street_number = addresComponent .getElementById ('display'). InnerHTML + '& lt; div & gt; Street number:' + street_number + '& lt; / div & gt;'}}}})}}; } / ** * geocodeResponse is filled with an object address data. * This function will be the right price * * "fish" for example: type = 'postal_code' = & gt; * GeocodeResponse.address_components [5] .types [1] = 'postal_code' * geocodeResponse.address_components [5] .long_name = '1000' * * type = 'route' = & gt; * GeocodeResponse.address_components [1] .types [1] = 'route' * geocodeResponse.address_components [1] .long_name = 'Wetstraat' * / function addresComponent (type, geocodeResponse) {for (I = 0; I & LT ; GeocodeResponse .address_components.length; i ++) {(For j j = 0; j & lt; geocodeResponse.address_components [i] .types.length; J ++) {if (geocodeResponse.address_components [i] .types [J] == type) {return geocodeResponse.address_components [i] .long_name; }}} Return ''; } & Lt; / Script & gt; & Lt; / Head & gt; & Lt; Body onload = "init ()" & gt; & Lt; Div id = "map-canvas" & gt; & Lt; / Div & gt; & Lt; Div id = "display" & gt; & Lt; / Div & gt; & Lt; H3 & gt; Drag the marker - See some address element & lt; / H3 & gt; & Lt; / Body & gt; & Lt; / Html & gt;
Comments
Post a Comment