如何在infowindow中显示每个标记的latlong位置 [英] how to show latlong position of each marker in infowindow

查看:73
本文介绍了如何在infowindow中显示每个标记的latlong位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望在点击它们时显示infowindow中每个标记的latlng位置





i want to show the latlng position on each marker in infowindow when i m click on them


<!DOCTYPE html>
<html>
  <head>
    <title>Remove Markers</title>
    <style>
      html, body, #map-canvas {
        height: 100%;
        margin: 0px;
        padding: 0px
      }
      #panel {
        position: absolute;
        top: 5px;
        left: 50%;
        margin-left: -180px;
        z-index: 5;
        background-color: #fff;
        padding: 5px;
        border: 1px solid #999;
      }
    </style>
    <script src="https://maps.googleapis.com/maps/api/js?v=3.exp"></script>
    <script>
// In the following example, markers appear when the user clicks on the map.
// The markers are stored in an array.
// The user can then click an option to hide, show or delete the markers.
var map;
var markers = [];

function initialize() {
  var haightAshbury = new google.maps.LatLng(37.7699298, -122.4469157);
  var mapOptions = {
    zoom: 12,
    center: haightAshbury,
    mapTypeId: google.maps.MapTypeId.TERRAIN
  };
  map = new google.maps.Map(document.getElementById('map-canvas'),
      mapOptions);

  // This event listener will call addMarker() when the map is clicked.
  google.maps.event.addListener(map, 'click', function(event) {
    addMarker(event.latLng);
  });

  // Adds a marker at the center of the map.
  }

// Add a marker to the map and push to the array.
function addMarker(location) {
  var marker = new google.maps.Marker({
    position: location,
    map: map
  });
  markers.push(marker);
}

// Sets the map on all markers in the array.
function setAllMap(map) {
  for (var i = 0; i < markers.length; i++) {

    markers[i].setMap(map);

  }

}



// Removes the markers from the map, but keeps them in the array.

function clearMarkers() {

  setAllMap(null);

}



// Shows any markers currently in the array.

function showMarkers() {

  setAllMap(map);

}



// Deletes all markers in the array by removing references to them.

function deleteMarkers() {

  clearMarkers();

  markers = [];

}



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



    </script>
  </head>
  <body>
    <div id="panel">
      <input onclick="clearMarkers();" type=button value="Hide Markers">
      <input onclick="showMarkers();" type=button value="Show All Markers">
      <input onclick="deleteMarkers();" type=button value="Delete Markers">
    </div>
    <div id="map-canvas"></div>
    <p>Click on the map to add markers.</p>
  </body>
</html>

推荐答案

http://stackoverflow.com/questions/6374329/get-latitude-and-longitude-of-marker-onclick [ ^ ]



< a href =https://www.mapbox.com/mapbox.js/example/v1.0.0/select-center-form/> https://www.mapbox.com/mapbox.js/example/v1。 0.0 / select-center-form / [ ^ ]



查看这些链接,它可能对您有帮助。
http://stackoverflow.com/questions/6374329/get-latitude-and-longitude-of-marker-onclick[^]

https://www.mapbox.com/mapbox.js/example/v1.0.0/select-center-form/[^]

Check those links, it may help you.


这篇关于如何在infowindow中显示每个标记的latlong位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆