1
Good Afternoon Guys, I have the following code below and I would like to know how to include the address in the Marker, because I own the lat and lng in the database of all points. (That and a gps)
var image = '../assets/img/ambulance.png';
var map;
var markers = [];
var zoomLevel = 12;
var centerPos = new google.maps.LatLng(-23.4745571, -46.5359114);
var latlngbounds = new google.maps.LatLngBounds();
function initialize() {
var mapOptions = {
center: centerPos,
zoom: zoomLevel
};
map = new google.maps.Map(document.getElementById("mapCanvas"), mapOptions);
var trafficLayer = new google.maps.TrafficLayer();
trafficLayer.setMap(map);
}
function setMapOnAll(map) {
for (var i = 0; i < markers.length; i++) {
markers[i].setMap(map);
}
markers = [];
}
ON THAT AND WHERE I DECLARE WHAT WILL APPEAR IN THE MARKER, BUT I WANTED TO CONVERT THE lat and Lon that is recorded in the bank to address;
function doLoad() {
$.ajax({
type: 'post',
url: 'dispositivos/db.php',
data: {
action: 'getPos'
},
cache: false,
dataType: "json",
success: function(retorno) {
setMapOnAll(null);
var infowindow = new google.maps.InfoWindow();
var marker;
for (var i = 0; i < retorno.length; i++) {
marker = new google.maps.Marker({
position: new google.maps.LatLng(retorno[i].lat, retorno[i].lon),
map: map,
icon: image
});
markers.push(marker);
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
var iwContent = '<div id="iw_container">' + '<div class="iw_title"><b>' + retorno[i].responsavel + '</b></div>' + '<div class="iw_content">' + '<b>Data/Hora:</b> ' + retorno[i].cadastro + '</b></div>' + '<div class="iw_title">' + '<b>Telefone:</b> ' + retorno[i].numero + ' </b></div>' + '<div class="iw_title">' + '<b>Endereço:</b> ' + retorno[i].lat + ' </b></div>' + retorno[i].lon + ' </div></div>';
infowindow.setContent(iwContent);
infowindow.open(map, marker);
}
})(marker, i));
google.maps.event.addListener(map, 'click', (function(marker, i) {
return function() {
infowindow.close();
}
})(marker, i));
}
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
//alert(JSON.stringify(XMLHttpRequest, null, 2));
}
});
}
function cityByLatLng(latitude, longitude) {
var geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(latitude, longitude);
geocoder.geocode({
'location': latlng
}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (results[0]) {
document.getElementById('seu elemento').value = results[0].formatted_address;
} else {
window.alert('No results found');
}
} else {
window.alert('Geocoder failed due to: ' + status);
}
});
}
function FormatNumberLength(num, length) {
var r = "" + num;
while (r.length < length) {
r = "0" + r;
}
return r;
}
function atualiza() {
var d = new Date();
var hora = FormatNumberLength(d.getHours(), 2);
var min = FormatNumberLength(d.getMinutes(), 2);
var seg = FormatNumberLength(d.getSeconds(), 2);
$("#txtTime").val(hora + ':' + min + ':' + seg);
doLoad();
}
// Initialize when page loads
jQuery(function() {
initialize();
setInterval(function() {
atualiza();
}, 5000);
$('#full').click(function() {
$('#mapCanvas').fullscreen();
return false;
});
$("#btnCarregar").click(function() {
atualiza();
})
});