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

javascript - google maps API v3 set marker and get point - Stack Overflow

programmeradmin3浏览0评论

I have a problem to set marker and get latitude and longitude for that marker. How can I do that in google maps v3 API

var myLatlng = new google.maps.LatLng(-34.397, 150.644);
        var myOptions = {
          zoom: 8,
          center: myLatlng,
          mapTypeId: google.maps.MapTypeId.ROADMAP
        };
var map = new google.maps.Map(document.getElementById("divGoogleMaps"), myOptions);

google.maps.event.addListener(map, 'click', function() {

});

this is my start code.

I have a problem to set marker and get latitude and longitude for that marker. How can I do that in google maps v3 API

var myLatlng = new google.maps.LatLng(-34.397, 150.644);
        var myOptions = {
          zoom: 8,
          center: myLatlng,
          mapTypeId: google.maps.MapTypeId.ROADMAP
        };
var map = new google.maps.Map(document.getElementById("divGoogleMaps"), myOptions);

google.maps.event.addListener(map, 'click', function() {

});

this is my start code.

Share Improve this question edited Dec 24, 2014 at 19:52 ROMANIA_engineer 56.7k30 gold badges209 silver badges205 bronze badges asked Aug 16, 2011 at 18:38 user821738user821738 611 gold badge1 silver badge4 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 4

You should check Google Maps API doc web-site they have a fex example to help you started.

http://code.google./apis/maps/documentation/javascript/basics.html

google.maps.event.addListener(map, 'click', function(e) {
          placeMarker(e.latLng, map);
        });
      }

      function placeMarker(position, map) {
        var marker = new google.maps.Marker({
          position: position,
          map: map
        });
        map.panTo(position);
      }

Here you set a marker and get the position.

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

Taken directly from Google Maps API v3

If you want to attach an event listener to the marker, it is advisable to do it right after you add it to the map, while you still have a fresh reference to it (in the case where you're potentially looping through some marker adding code, as is mon).

发布评论

评论列表(0)

  1. 暂无评论