Next Previous

Maps API Add Marker

29

The first step is to instantiate the Google Maps Map object where you want to add a marker into.

  var map = new google.maps.Map(document.getElementById("map"), {
      zoom: 13
      center: new google.maps.LatLng(45.424721, -75.695000),
      mapTypeId: google.maps.MapTypeId.ROADMAP
    });

In the below example, I use the latitude and longitude of Ottawa city to make it the center of the map.

Then, instantiate marker object with a javascript object as a parameter.

marker = new google.maps.Marker({
    position: new google.maps.LatLng(45.424807 -75.699234),
    map: map
});
property namevalue
positionThe value is LatLng object with actual latitude and longitude of a place where the marker is going to be pinned. i.e 45.424807 -75.699234 are latitude and longitude values of parliament hill Ottawa
mapThe Actual actual Google Maps Map Object.

There you have it

Next Previous