未捕获的referenceError - Phonegap

时间:2013-07-22 18:31:55

标签: javascript cordova

我尝试使用google api v3制作地图。但我找到了它。这个错误是什么意思?

logcat eclipse

这是我的代码:

<!doctype html>
<html>

<head>
<meta charset="utf-8">
<title>Geolocation</title>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<!--
Include the maps javascript with sensor=true because this code is using a
sensor (a GPS locator) to determine the user's location.
See: https://developers.google.com/apis/maps/documentation/javascript/basics#SpecifyingSensor
-->
//<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=true"></script>

<link rel="stylesheet" href="jquery.mobile-1.3.1/jquery.mobile-1.3.1.min.css" />
<script src="jquery.mobile-1.3.1/jquery-1.9.1.min.js"></script>
<script src="jquery.mobile-1.3.1/jquery.mobile-1.3.1.min.js"></script>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true&libraries=places&language=id"></script>
<script type="text/javascript">



var map;

此函数初始化方向

function initialize() {
directionsDisplay = new google.maps.DirectionsRenderer();
var node = new google.maps.LatLng(-7.276442,112.791174);
var mapOptions = {
zoom: 15,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById('map'),
  mapOptions);
directionsDisplay.setMap(map);

navigator.geolocation.getCurrentPosition(function(position) {
  pos = new google.maps.LatLng(position.coords.latitude,
                                   position.coords.longitude);

  var marker = new google.maps.Marker({
        position : pos,
        map: map,
        title:'Lokasi Anda'
  });
  var marker1 = new google.maps.Marker({
        position : node,
        map: map,
        title:'Lokasi Anda'
  });

  // map.setCenter(pos);
  var bounds = new google.maps.LatLngBounds();
  bounds.extend(marker.getPosition());
  bounds.extend(marker1.getPosition());
  map.fitBounds(bounds);
  calcRoute(pos,node);
  }, function() {
  handleNoGeolocation(true);
});

}

如果发生失败,将运行此功能

function handleNoGeolocation(status) {
  alert("Geolocation failed");
  var node = new google.maps.LatLng(-7.276442,112.791174);
  var pos = new google.maps.LatLng(-7.5360639, 112.23840169999994);

  var marker = new google.maps.Marker({
        position : pos,
        map: map,
        title:'Lokasi Anda'
  });
  var marker1 = new google.maps.Marker({
        position : node,
        map: map,
        title:'Lokasi Anda'
  });
  var bounds = new google.maps.LatLngBounds();
  bounds.extend(marker.getPosition());
  bounds.extend(marker1.getPosition());
  map.fitBounds(bounds);
  calcRoute(pos,node);
}



google.maps.event.addDomListener(window, 'load', initialize);

为了指导,我调用了这个函数

function calcRoute(pos,node) {
var directionsService = new google.maps.DirectionsService();
var request = {
  origin:pos,
  destination:node,
  travelMode: google.maps.DirectionsTravelMode.DRIVING
};

directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
  directionsDisplay.setDirections(response);
} else { alert("Directions failed: "+status); }
});
}



</script>

这是我的HTML

</head>
<body>
<div id="gps_map" data-role="page">
<div data-role="header">
<h1>examples</h1>
</div>
<div data-role="content">
  <div id="map" style="height:390px;"></div>
  <a id="ok" data-role="button" data-icon="refresh">Refresh</a>
</div>
</div>
</body>
</html>

该错误的含义是什么?对不起,我是编码的新手。

0 个答案:

没有答案