2013-03-29 7 views
24

In meinem Domain-Modell, für die Entitäten in Frage, ich habe den:Platz Marker von Namen, Adresse und Postleitzahl

  • Namen des Orts (zB Wassersteine ​​Wakefield)
  • Die Straße Adressen (zB 61-62 Bishopgate-Weg)
  • Und die Postleitzahl (zB WF1 1YB)

aus dem obigen drei Informationen, wie kann ich eine Markierung auf der Karte platziert? Ich verwende Google Maps API 3.

Dank

+0

Ein Detail Blog: http : //goo.gl/d8w1J0 –

+1

@SureshKamrushi Sie nennen es ein "Detail-Blog", aber es ist nur ein Code-Snippet ohne Erklärung, wie es funktioniert. – WongKongPhooey

Antwort

41

dieses Beispiel:

HERE THE ORIGINAL

HTML

 <body onload="initialize()"> 
     <div> 
      <input id="address" type="text" value="Sydney, NSW"> 
      <input type="button" value="Geocode" onclick="codeAddress()"> 
     </div> 
     <div id="map-canvas" style="height:90%;top:30px"></div> 
     </body> 

JS

<script> 
    var geocoder; 
    var map; 
    function initialize() { 
    geocoder = new google.maps.Geocoder(); 
    var latlng = new google.maps.LatLng(-34.397, 150.644); 
    var mapOptions = { 
     zoom: 8, 
     center: latlng, 
     mapTypeId: google.maps.MapTypeId.ROADMAP 
    } 
    map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions); 
    } 

    function codeAddress() { 
    var address = document.getElementById('address').value; 
    geocoder.geocode({ 'address': address}, function(results, status) { 
     if (status == google.maps.GeocoderStatus.OK) { 
     map.setCenter(results[0].geometry.location); 
     var marker = new google.maps.Marker({ 
      map: map, 
      position: results[0].geometry.location 
     }); 
     } else { 
     alert('Geocode was not successful for the following reason: ' + status); 
     } 
    }); 
    } 
</script> 
+0

Danke für die Bearbeitung. Also wird der [address] Eingang, der Name, die Straße und die Postleitzahl auf einmal durch Kommas getrennt genommen? – Ciwan

+0

Entschuldigung, ich habe die falsche exmpale eingefügt, sehen Sie sich die Bearbeitung – grigno

+0

versuchen Sie direkt https://google-developers.appspot.com/maps/documentation/javascript/examples/geocoding-simple Es ist von Gmaps docs. – grigno