0

I am trying to display a simple marker on my map. I follow all the steps as shown in the example but no markers attaches.

this is the block with script: which is the bug?

why don not I see the marker?

<script type="text/javascript">
  function initialize() {
    var myOptions = {
      zoom: 8,
      center: new google.maps.LatLng(43.1711696, 11.351473),
      mapTypeId: google.maps.MapTypeId.ROADMAP
    };
   var map = new google.maps.Map(document.getElementById('object_map'),

        myOptions);  
        var marker= new google.maps.Marker ({ 
        position: LatLng, 
        title:"Mandolino"}); 

 }

   google.maps.event.addDomListener(window, 'load', initialize)


</script>
4
  • 1
    Care to share (that rhymes) your code ? v2 or v3 ? (p.s. i didnt downvote) Commented Feb 24, 2012 at 17:09
  • May u show me how to add markers? Commented Feb 24, 2012 at 18:57
  • You didnt create a marker ... what is LatLng ? Commented Feb 24, 2012 at 19:03
  • why not? this is the code found on google example...latlng means latitudelongitude Commented Feb 24, 2012 at 19:13

1 Answer 1

1

Simple example of creating markers on a map :

// this is list of markers with title / long and lat
var locations = [
      ['Bondi Beach', -33.890542, 151.274856, 4],
      ['Coogee Beach', -33.923036, 151.259052, 5],
      ['Cronulla Beach', -34.028249, 151.157507, 3],
      ['Manly Beach', -33.80010128657071, 151.28747820854187, 2],
      ['Maroubra Beach', -33.950198, 151.259302, 1]
];

// This creates the map with zoom level / default center and map type
var map = new google.maps.Map(document.getElementById('map'), {
  zoom: 10,
  center: new google.maps.LatLng(-33.92, 151.25),
  mapTypeId: google.maps.MapTypeId.ROADMAP
});

// this loops the array of marker locations
for (i = 0; i < locations.length; i++) { 
  // this creates the markers and adds them to the map 
  marker = new google.maps.Marker({
     position: new google.maps.LatLng(locations[i][1], locations[i][2]),
     map: map
  });
}

Working example : http://jsfiddle.net/QvNUF/95/

Update

To add a single marker do this :

var marker = new google.maps.Marker({
     position: new google.maps.LatLng(<yourlat>, <yourlong>),
     map: <yourmap>
});

you will need to replace <yourlat> with the latitude of the marker position, <yourlong> with the longitude of your marker position and <yourmap> with the map variable you created

Sign up to request clarification or add additional context in comments.

9 Comments

Var marker is not the marker?? this is what I found on google tutorial
I have updated my answer - you need to actually create a new google.maps.Marker object
This is what I found as example...so may you type the right code?
Create a jsfiddle.net with your code and then post a link to it here i will take a look
here is...I do not have result! However I see the map in the div id but do not see marker jsfiddle.net/mandolino/TNC4N/1
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.