最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Adding a marker to GMaps (google maps) - Stack Overflow

programmeradmin5浏览0评论

I'm trying to use this tool: / to add colour to my google map, here is my example:

/

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.

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

http://jsfiddle/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.

Share Improve this question edited Apr 9, 2013 at 17:06 user1738017 asked Apr 9, 2013 at 16:38 user1738017user1738017 6272 gold badges12 silver badges29 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 7

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

Demo forked from your example: http://jsfiddle/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);
        });

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/xUUxn/854/

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);
});
发布评论

评论列表(0)

  1. 暂无评论