我已创建谷歌地图方向,它在localhost中工作完美,但是当我上传到我的服务器时,地图不会显示。
我检查了所有的代码,似乎没有错。 即使我尝试在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"/> ⇒ Ke ⇒
<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>