Answer the question
In order to leave comments, you need to log in
Google Maps - marks and information windows for them
Good day!
There is a table with coordinates, after receiving these coordinates, you need to add markers to the Google Maps map and attach a specific info window to each marker, tell me how to do this? Here are my work:
var gmap = {
map : [],
markers : [],
init : function(){
var mapOptions = {
zoom: 15,
};
map = new google.maps.Map(document.getElementById('map-canvas'),
mapOptions);
google.maps.event.addListener(map, 'click', function(coordinates) {
var coords = {
lat : coordinates.latLng.d,
lng : coordinates.latLng.e,
};
gmap.addMarker(map,coords);
});
gmap.geo();
},
loadMarkers : function(data){
/* как сделать вывод маркеров и инфоокон? */
}
addMarker : function(mapObj,coords){
var marker = new google.maps.Marker({
position: coords,
map: mapObj,
icon: 'img/marker-32x32.png',
animation: google.maps.Animation.DROP,
});
listener.tmp.marker = marker; //удалит маркер, если модальное окно будет закрыто
dialog.addPlace(marker);
},
deleteMarker : function(marker){
marker.setMap(null);
},
geo : function(){
// Try HTML5 geolocation
if(navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
var pos = new google.maps.LatLng(position.coords.latitude,position.coords.longitude);
var infowindow = new google.maps.InfoWindow({
map: map,
position: pos,
content: 'Location found using HTML5.'
});
map.setCenter(pos);
}, function() {
gmap.geoError(true);
});
} else {
// Browser doesn't support Geolocation
gmap.geoError(false);
}
},
geoError : function(errorFlag) {
if (errorFlag) {
var content = 'Error: The Geolocation service failed.';
} else {
var content = 'Error: Your browser doesn\'t support geolocation.';
}
var options = {
map: map,
position: new google.maps.LatLng(-34.397, 150.644),
content: content
};
var infowindow = new google.maps.InfoWindow(options);
map.setCenter(options.position);
},
};
google.maps.event.addDomListener(window, 'load', gmap.init);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question