简体   繁体   English

在叠加地图中显示纬度

[英]display lat lon in overlay maps

i have an overlay maps and this is the code (CODE:A)我有一个覆盖图,这是代码(代码:A)

var overlay;
  USGSOverlay.prototype = new google.maps.OverlayView();

  // Initialize the map and the custom overlay.

  function initMap() {
    var map = new google.maps.Map(document.getElementById('map'), {
      zoom: 5,
      center: {lat: -2.548926, lng: 118.0148634},
      mapTypeId: google.maps.MapTypeId.roadmap
    });

    var bounds = new google.maps.LatLngBounds(
        new google.maps.LatLng(-21.44555, -272.788888),
        new google.maps.LatLng(16.776667, -212.22222));

    var srcImage = 'http://localhost/komposat/no2.png';

    overlay = new USGSOverlay(bounds, srcImage, map);
  }

  function USGSOverlay(bounds, image, map) {

    // Initialize all properties.
    this.bounds_ = bounds;
    this.image_ = image;
    this.map_ = map;


    this.div_ = null;


    this.setMap(map);
  }

  USGSOverlay.prototype.onAdd = function() {

    var div = document.createElement('div');
    div.style.borderStyle = 'none';
    div.style.borderWidth = '0px';
    div.style.position = 'absolute';


    var img = document.createElement('img');
    img.src = this.image_;
    img.style.width = '100%';
    img.style.height = '100%';
    img.style.position = 'absolute';
    div.appendChild(img);

    this.div_ = div;
    this.div_.style.opacity = 0.5;


    var panes = this.getPanes();
    panes.overlayLayer.appendChild(div);
  };

    var sw = overlayProjection.fromLatLngToDivPixel(this.bounds_.getSouthWest());
    var ne = overlayProjection.fromLatLngToDivPixel(this.bounds_.getNorthEast());

    // Resize the image's div to fit the indicated dimensions.
    var div = this.div_;
    div.style.left = sw.x + 'px';
    div.style.top = ne.y + 'px';
    div.style.width = (ne.x - sw.x) + 'px';
    div.style.height = (sw.y - ne.y) + 'px';
  };

  USGSOverlay.prototype.onRemove = function() {
    this.div_.parentNode.removeChild(this.div_);
    this.div_ = null;
  };


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

i want display lat and lng a location when the maps clicked by user.我想在用户单击地图时显示 lat 和 lng 位置。 and this is the code (CODE:B)这是代码(代码:B)

google.maps.event.addListener(map, 'click', function( event )
            {
                  alert( "Latitude: "+event.latLng.lat()+" "+", longitude: "+event.latLng.lng() ); 

              });

i want to display lat and lng wherever user wants in my overlay map.我想在我的覆盖图中用户想要的任何地方显示 lat 和 lng。 i put my code:B inside the initMap function in code:A, but it didnt work.我将我的代码:B 放在代码:A 中的 initMap 函数中,但它不起作用。 so can you guys help me solve this?所以你们能帮我解决这个问题吗? thanks.谢谢。

Try this..If it doesn't work then share your code at jsfiddle试试这个..如果它不起作用,那么在 jsfiddle 分享你的代码

 google.maps.event.addListener(map, "click", function (event) { 
            var latitude = event.latLng.lat();
        var longitude = event.latLng.lng();
        console.log( latitude + ', ' + longitude );
        alert(latitude + ', ' + longitude);
      });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 地理位置-如何在文本框中显示经纬度 - Geolocation - how to display lat/lon in a textbox 如何通过Google Maps Geocoding而不是lon和lat使用地址 - How to use an address with Google Maps Geocoding and not with lon and lat 尝试使用Google Maps用户界面在Django中绘制Lat / Lon - Trying to use a Google Maps user interface to caputre Lat/Lon in Django 在angular-google-maps中将地址转换为纬度/经度 - Convert address to lat/lon in angular-google-maps Google Maps Markers位置错误,但经/纬度显示正确 - Google Maps Markers in wrong location, but lat/lon appears correct 如何在谷歌地图上显示具有相同纬度和经度的多个标记 - How to show multiple markers with the same Lat and Lon on google maps Map 圆圈覆盖到谷歌地图中的纬度/经度和半径 - Map circle overlay to lat/lng and radius in Google Maps 获取多边形中每个点的纬度和经度-Google Maps API v3 - Get lat and lon for each point in polygon - Google Maps API v3 如何检查坐标的对(纬度和纬度)是否接近Google地图上的主干道或高速公路? - How to check if pair (lat and lon) of coordinates is close to arterial road or highway on Google Maps? Google Maps javascript-标记数组,如何获取经纬度? - Google maps javascript - Marker array, how do I get the lat/lon?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM