Tuesday 15 September 2015

javascript - Google Maps Geocoding API -


The following code displays the map and also the div part but can not display the marker point on the map, no one can help me Thanks in advance!

  & lt ;! DOCTYPE html & gt; & Lt; Html & gt; & Lt; Top & gt; & Lt; Script src = "https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false" & gt; & Lt; / Script & gt; & Lt; Script & gt; Var myCenter = new google.maps.LatLng (17.3820 9494787750578831396484375); Var Geododer, Map; Start the function () {geocoder = new google.maps.Geocoder (); Var mapProp = {center: myCenter, Zoom: 5, maptype: google.maps.MapTypeId.ROADMAP}; Var map = new google.maps.Map (document.getElementById ("googleMap"), mapProp); } Function codeAddress () {var address = document.getElementById ('address'). Values; Geocoder.geocode ({'address': address}, function (result, status) {if (position === google.maps.GeocoderStatus.OK) {map.setCenter (result [0] .geometry.location); var marker = New google.maps.Marker ({map: map, position: result [0] .geometry.location});} and {warnings ('Geocode was not successful for the following reason:' position);}}); } Google.maps.event.addDomListener (window, 'load', start); & Lt; / Script & gt; & Lt; / Head & gt; & Lt; Body & gt; & Lt; Div id = "pannel" & gt; & Lt; Input type = "address" type = "textbox" value = "HeaderBad, Andhra Pradesh" & gt; & Lt; Input type = "button" value = "geographic" onclick = "codeAddress ();" & Gt; & Lt; / Div & gt; & Lt; Div id = "google map" style = "width: 1200px; height: 800px;" & Gt; & Lt; / Div & gt; & Lt; / Body & gt; & Lt; / Html & gt;    

In order for your code to work, you need two things:

  1. Make sure your input field has a id attribute (because you're using document.getElementById )
  2. Do not resume "value" = headers, Andhra Pradesh "& gt;

    More map immediacy:

      map = new google.maps.Map (document.getElementById ("googleMap"), mapProp);   

    Here's the full code:

         

No comments:

Post a Comment