我只是试图让我的谷歌地图插件工作。 这里我的代码,我只是迄今写:GMaps API - 无回应
<html class="ui-mobile">
<head>
............
<script type="application/javascript" src="js/jquery-2.1.0.js"></script>
<script type="application/javascript" src="js/jquery.mobile-1.4.2.min.js"></script>
.............
<script type="text/javascript" src="https://maps.google.com/maps/api/js?v=3.exp&sensor=true"> </script>
<script type="text/javascript">
var fromLat = 0.000;
var fromLng = 0.000;
var toLat;
var toLng;
var mapcontainer;
var map;
var directionsDisplay;
var directionsService = new google.maps.DirectionsService();
function onGeoGetSuccess (p){
fromLat = parseFloat(p.coords.latitude);
fromLng = parseFloat(p.coords.longitude);
alert("run"); //is fired
calcRoute();
}
function onGeoGetFail(e){
fromLat = 0.00;
fromLng = 0.00;
alert("fail");
}
function calcRoute() {
var request = {
origin: new google.maps.LatLng(fromLat, fromLng),
destination:new google.maps.LatLng(toLat, toLng),
travelMode: google.maps.TravelMode.WALKING
};
directionsService.route(request, function(response, status) {
alert("status "+status)
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
}
});
}
function initGmap(){
directionsDisplay = new google.maps.DirectionsRenderer();
var mapOptions = {
zoom: 7,
disableDefaultUI : true,
draggable : false,
keyboardShortcuts : false,
scrollwheel : false,
mapTypeId: google.maps.MapTypeId.WALKING
}
map = new google.maps.Map(mapcontainer.find(".map-canvas").get(0), mapOptions);
directionsDisplay.setMap(map);
directionsDisplay.setPanel(t.find(".mapcontainer").get(0));
}
///// just to show - this is triggered on a subpage which is autoloaded by jquery mobile
$(".building_page").on("pageshow",function(){
t = $(this)
c = t.attr('data-destination').split(',');
toLat = c[0];
toLng = c[1];
mapcontainer = t;
google.maps.event.addDomListener(t, 'load', initGmap);
navigator.geolocation.getCurrentPosition(onGeoGetSuccess, onGeoGetFail);
});
</script>
</head>
<body >
<ul class="nativeDroidCards">
<li>.........</li>
<li>........</li>
<li id="building_E_map" >
<div class="map-canvas"></div>
<div class="mapcontainer"></div>
<a href="maps:q=dfsfdsfdsfffdsf"><i class="icon-screenshot"></i>Navigation </a>
</li>
</ul>
</body>
</html>
我可以说,一切都被触发罚款,纬度经度设置正确,该设备的地理位置是正确的usw.
但我的容器是空的,没有错误。没有。 我调试了下来,所以很明显:
directionsService.route(request, function(response, status) {
alert("status "+status)
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
}
});
从来没有命中。它从未叫过。 但也没有任何错误被解雇。
只是,...可笑。
有什么想法吗?
在此先感谢
什么行动会导致地图显示?您的发布代码中没有任何内容会使这一点变得明显。 – geocodezip