[英]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.