i have an overlay maps and this is the code (CODE: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. and this is the code (CODE: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. i put my code:B inside the initMap function in code:A, but it didnt work. so can you guys help me solve this? thanks.
Aucun commentaire:
Enregistrer un commentaire