0

我已经创建了谷歌地图方向,它在本地主机中完美地工作,但是当我上传到我的服务器时,地图不显示。

我检查了所有代码,似乎没有任何问题。即使我尝试在 localhost 上运行它,一切都很顺利。

这是我的代码:

<div class="direktion_form">
Dari : <input id="lokasiku" name="lokasiku" type="radio" value="lokasiku" checked /> <strong>Lokasiku</strong> atau 
<input type="text" class="xlarge" id="from" placeholder="Lokasi lain"/> &rArr; Ke &rArr; 
<input type="text" class="xlarge" id="to" value="<?php echo $data['alamat']; ?>, <?php echo $data['kota']; ?>, Indonesia" disabled />
<button class="btn info" onclick="calcRoute()">Penunjuk Arah</button>
</div>

js脚本:

var directionsDisplay;
var directionsService = new google.maps.DirectionsService();
var map;

function initialize() {

    var mapOptions = {
      zoom: 15,
      center: new google.maps.LatLng(<?php echo $data['latitude']; ?>, <?php echo $data['longitude']; ?>),
      mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    var map = new google.maps.Map(document.getElementById("map"),mapOptions);

    var panel_div = document.getElementById("panel");
    var rendererOptions = {
      draggable : true,
      panel : panel_div
    }
    directionsDisplay = new google.maps.DirectionsRenderer(rendererOptions);
    directionsDisplay.setMap(map);

    google.maps.event.addListener(marker, 'click', function() {
        infowindow.open(map);
        map.setZoom(16);
        map.setCenter(marker.getPosition());
    });

}


function calcRoute() {
    navigator.geolocation;
    navigator.geolocation.getCurrentPosition(function(position) {
        initialLocation = position.coords.latitude+","+position.coords.longitude;

        if($('#from').val() != "") {
            var start = $("#from").val();   
        } else { var start = initialLocation; }

        var end = "<?php echo $data['latitude']; ?>, <?php echo $data['longitude']; ?>";

        var request = {
            origin:start,
            destination:end,
            travelMode: google.maps.TravelMode.DRIVING
        };
        directionsService.route(request, function(result, status) {
            if (status == google.maps.DirectionsStatus.OK) {
                directionsDisplay.setDirections(result);
            }
        });
    });
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
4

0 回答 0