Red
Red

Reputation: 2246

Google Maps Javascript API

I know that you can put a marker on a long/lat coordinate, but I am having a hard time finding where/how you can place a marker on a specific street address. Can anyone tell me how to do this? I am using V3 of the API and JQuery.

Upvotes: 2

Views: 551

Answers (3)

midwinterday
midwinterday

Reputation: 11

@James has pointed out how to run a geocoding request, but you can take advantage of a jQuery plugin like landcarte to make it shorter and clearer like that:

var map = $("#map").geoMap();
map.search("Copenhagen", function(data) {
  if (data.location) map.add("marker", data.location);
});

Upvotes: 0

James
James

Reputation: 1851

Right, basically query the maps API by address through a call to Geocoder. It should return to you a LAT/LNG which then you can use to create a marker.

function mygeocoder(addr){
  var geocoder = new google.maps.Geocoder();

    if (geocoder) {
      geocoder.geocode({ 'address': addr }, function (results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
          console.log("LAT: ", results[0].geometry.location.lat());
          console.log("LNG: ", results[0].geometry.location.lng());
        }
    else {
       console.log("Geocoding failed: " + status);
    }
      });
   }
 }

Upvotes: 2

Peter Smith
Peter Smith

Reputation: 889

You will need to run a geocoding query.

View this source for details: http://code.google.com/apis/maps/documentation/javascript/examples/geocoding-simple.html

Upvotes: 1

Related Questions