Click here to Skip to main content
14,920,935 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to place markers in different locations in a map but it seems to not be working.

What I have tried:

Info Windows

/* Always set the map height explicitly to define the size of the div
* element that contains the map. */
#map {
height: 100%;
/* Optional: Makes the sample page fill the window. */
html, body {
height: 100%;
margin: 0;
padding: 0;

// This example displays a marker at the center of Australia.
// When the user clicks the marker, an info window opens.

function initMap() {
var durban = { lat: 29.8536, lng: 31.0061 };
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 10,
center: durban

var contentString = ''+
'Durban, also referred to as Ayers Rock, is a large ' +
'sandstone rock formation in the southern part of the '+
'Northern Territory, central Australia. It lies 335 km (208 mi) '+
'south west of the nearest large town, Alice Springs; 450 km '+
'(280 mi) by road. Kata Tjuta and Uluru are the two major '+
'features of the Uluru - Kata Tjuta National Park. Uluru is '+
'sacred to the Pitjantjatjara and Yankunytjatjara, the '+
'Aboriginal people of the area. It has many springs, waterholes, '+
'rock caves and ancient paintings. Uluru is listed as a World '+
'Heritage Site.'+
'Attribution: Uluru, '+
' '+
'(last visited June 22, 2009).'+

var infowindow = new google.maps.InfoWindow({
content: contentString

var marker = new google.maps.Marker({
position: durban,
map: map,
title: 'Durban (Ayers Rock)'
marker.addListener('click', function() {, marker);


F-ES Sitecore 21-Sep-18 4:34am
We don't know if you are importing the right script files, we don't know if or how you are calling initMap, we don't know if there is an element on your page with an id of 'map' and so on. We can't diagnose issues from an out of content scrap of code. Check for errors in the console, use the debugger to step through your code line by line to see what is happening. Or find another example of how you put a marker on a google map, there are millions out there.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900