Google地图在localhost上加载,但无法在在线服务器上加载

时间:2014-09-10 14:08:10

标签: javascript php google-maps

我已经能够在localhost上部署谷歌地图,它会成功加载所有坐标。 但是当我将相同的代码上传到我的服务器时,它完全无法加载。我尽我所能,我真的迷失了。

<html>
<head>

<script type='text/javascript' src='jquery-1.6.2.min.js'></script>
<script type='text/javascript' src='jquery-ui-1.8.14.custom.min.js'></script>

<style>

    BODY {font-family : Verdana,Arial,Helvetica,sans-serif; color: #000000; font-size : 13px ; }

    #map_canvas { width:100%; height: 100%; z-index: 0; }
</style>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false" /></script>

<script type='text/javascript'>
jQuery(document).ready( function($){
        function closeInfos(){
            if(infos.length > 0){
                infos[0].set("marker",null);
                infos[0].close();
                infos.length = 0;
            }
        }

    //Get data, and replace it on the form
    var geocoder;
    var map;
    var markersArray = [];
    var infos = [];

    geocoder = new google.maps.Geocoder();
    var myOptions = {
          zoom: 9,
          mapTypeId: google.maps.MapTypeId.ROADMAP
        }
    var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);    

    function deleteMarkers() {
      for (var i = 0; i < markersArray.length; i++) {
        markersArray[i].setMap(null);
      }

      markersArray = [];
    }

setInterval(function(){
    $.get('ajax_gp_gps.php', function(data){        
     var bounds = new google.maps.LatLngBounds();
    var encodedString;
    var stringArray = [];
    encodedString = data;
    stringArray = encodedString.split("****");

    var x;
    for (x = 0; x < stringArray.length; x = x + 1)
    {
        var addressDetails = [];
        var marker;
        addressDetails = stringArray[x].split("&&&");

        var lat = new google.maps.LatLng(addressDetails[1], addressDetails[2]);
        //alert(image + " " + addressDetails[1] );
        marker = new google.maps.Marker({ 
            map: map, 
            position: lat,
            content: addressDetails[0]
        });
        markersArray.push(marker);
        google.maps.event.addListener( marker, 'click', function () {
            closeInfos();
            var info = new google.maps.InfoWindow({content: this.content});
            // where I have added .html to the marker object.
            //infowindow.setContent( marker.html);
            info.open(map,this);
            infos[0]=info;
        });
        bounds.extend(lat);
    }

    map.fitBounds(bounds);


    });
},1000);

});     
</script>

</head>
<body>

<?php include_once("ajax_gp_gps.php"); ?>

<div id='input'>
  <input type="hidden" id="encodedString" name="encodedString" value="<?php echo $encodedString; ?>">
</div>
<div id="map_canvas"></div>

</body>
</html>

1 个答案:

答案 0 :(得分:0)

如果您的在线域名有权访问,则需要检查Google API。