Good morning!
I hope you can help me, the php file shows me the google map with the correct latitude and longitude, this data comes from MySQL. If the map is displayed according to this data, there is only one DETAIL that does not show the marker (indicator) on the map. Annex the code that I have .. Thank you!
<?php
if($data->latitud=="" && $data->longitud==""){
$data->latitud="27.470182279368984";
$data->longitud="-99.50761556625366";
}else{
}
?>
<script src="http://maps.googleapis.com/maps/api/js?key=AIzaSyDY0kkJiTPVd2U7aTOAwhc9ySH6oHxOIYM&sensor=false"></script>
<script>
var map;
var myCenter = new google.maps.LatLng(<?php echo $data->latitud; ?>, <?php echo $data->longitud; ?>);
var marker = new Array();
var infowindow;
function initialize(){
var mapProp = {
center:myCenter,
zoom:16,
mapTypeId:google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("googleMap"),mapProp);
google.maps.event.addListener(map, 'click', function(event) {
/*map.removeMarker();
map.clearMarkers();*/
placeMarker(event.latLng);
});
}
// para poner un marcador
function placeMarker(location) {
if (!marker || !marker.setPosition) {
marker = new google.maps.Marker({
position: location,
map: map,
});
} else {
marker.setPosition(location);
}
if (!!infowindow && !!infowindow.close) {
infowindow.close();
}
infowindow = new google.maps.InfoWindow({
content: 'Latitud: ' + location.lat() + '<br>Longitud: ' + location.lng()
});
infowindow.open(map, marker);
$("#latitud").val(location.lat());
$("#longitud").val(location.lng());
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>