Adding a marker to GMaps (google maps)

﹥>﹥吖頭↗ 提交于 2019-12-06 11:38:15

问题


I'm trying to use this tool: http://software.stadtwerk.org/google_maps_colorizr/ to add colour to my google map, here is my example:

http://jsfiddle.net/xUUxn/851/

The colour works fine, but now I can't seem to add any markers to it, I've tried putting this example code in:

map.addMarker({ 
  lat: -12.043333,
  lng: -77.028333,
  title: 'Lima',
  infoWindow: {
    content: '<p>HTML Content</p>'
  }
 });

But it doesn't seem to work, I'm not entirely sure where to put it or even if the references are correct.


回答1:


In order to create a marker you need to do the following:

Demo forked from your example: http://jsfiddle.net/lucuma/xUUxn/852/

JS:

var marker = new google.maps.Marker({
        position: new google.maps.LatLng( -12.043333,-77.028333),
        map: map,
        title: 'Hello World!'
    });

To add an info window overlay:

var contentString = '<div id="content"><h1>Overlay</h1></div>';
  var infowindow = new google.maps.InfoWindow({
            content: contentString
  });


google.maps.event.addListener(marker, 'click', function() {
          infowindow.open(map,marker);
        });



回答2:


The documentation says:

var marker = new google.maps.Marker({
   position: new google.maps.LatLng(0,0),
   map: map,
   title:"Hello World!"
});

In your Fiddle: http://jsfiddle.net/xUUxn/854/




回答3:


I was able to use a loop, by this using 'this' as second parameters to to infoWindow.open()

google.maps.event.addListener(marker, 'click', function() {
    infowindow = new ....;
    infowindow.open(map,this);
});


来源:https://stackoverflow.com/questions/15907626/adding-a-marker-to-gmaps-google-maps

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!