I am making an ajax code request:
$.ajax({
type:"POST",
url:"url.php",
data:{
ida : href,
},
beforeSend: function(){
},
success:function(data){
$("#mapa").html(data);
}
});
Request is being made successfully, no problem. What happens is when loading the result, in case it is a map of google maps, it gives an error: You have included the Google Maps API multiple times on this page. This may cause unexpected errors.
My url.php file is:
<div id="gmap_canvas"></div>
<div id='map-label'></div>
<!-- JavaScript to show google map -->
<script type="text/javascript" src="http://maps.google.com/maps/api/js"></script><scripttype="text/javascript">
function init_map() {
var myOptions = {
zoom: 14,
center: new google.maps.LatLng(<?php echo $latitude; ?>, <?php echo $longitude; ?>),
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("gmap_canvas"), myOptions);
marker = new google.maps.Marker({
map: map,
position: new google.maps.LatLng(<?php echo $latitude; ?>, <?php echo $longitude; ?>)
});
infowindow = new google.maps.InfoWindow({
content: "<?php echo $formatted_address; ?>"
});
google.maps.event.addListener(marker, "click", function () {
infowindow.open(map, marker);
});
infowindow.open(map, marker);
}
google.maps.event.addDomListener(window, 'load', init_map);
</script>
I have nowhere else in the reference code to include the map scritp, it is loaded directly by the url.php file via ajax.
Accessing directly in the browser url.php works perfectly, if via ajax does not work, gives the error reported.
I would like to know why the error, since I am referencing the map script only once and not multiple times depending on the error reported.