Javascript Phonegap构建中的地理定位白屏

Javascript Phonegap构建中的地理定位白屏,javascript,css,mobile,geolocation,dreamweaver,Javascript,Css,Mobile,Geolocation,Dreamweaver,我试图在我的phonegap构建中显示跟踪用户位置的地图。我试着用这个例子 我已经将html css和js添加到我的应用程序中,并添加了 <feature name="http://api.phonegap.com/1.0/geolocation"/> <feature name="http://api.phonegap.com/1.0/network"/> 我使用的js代码是 <div role="main" class="ui-content" id="m

我试图在我的phonegap构建中显示跟踪用户位置的地图。我试着用这个例子

我已经将html css和js添加到我的应用程序中,并添加了

<feature name="http://api.phonegap.com/1.0/geolocation"/>
<feature name="http://api.phonegap.com/1.0/network"/> 
我使用的js代码是

<div role="main" class="ui-content" id="map-canvas"></div>
#map-page, #map-canvas { width: 100%; height: 100%; padding: 0; } 
<script>
$( document ).on( "pageinit", "#map-page", function() {
var defaultLatLng = new google.maps.LatLng(34.0983425, -118.3267434); // Default to        Hollywood, CA when no geolocation support
if ( navigator.geolocation ) {
function success(pos) {
// Location found, show map with these coordinates
drawMap(new google.maps.LatLng(pos.coords.latitude, pos.coords.longitude));
}
function fail(error) {
drawMap(defaultLatLng); // Failed to find location, show default map
}
// Find the users current position. Cache the location for 5 minutes, timeout after 6     seconds
navigator.geolocation.getCurrentPosition(success, fail, {maximumAge: 500000,      enableHighAccuracy:true, timeout: 6000});
} else {
drawMap(defaultLatLng); // No geolocation support, show default map
}
function drawMap(latlng) {
var myOptions = {
zoom: 10,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map-canvas"), myOptions);
// Add an overlay to the map of current lat/lng
var marker = new google.maps.Marker({
position: latlng,
map: map,
title: "Greetings!"
});
}
});
</script> 

$(document).on(“pageinit”,“映射页”,function()){
var defaultLatLng=new google.maps.LatLng(34.0983425,-118.3267434);//在没有地理位置支持时默认为加利福尼亚州好莱坞
if(navigator.geolocation){
功能成功(pos){
//找到位置,用这些坐标显示地图
drawMap(新的google.maps.LatLng(pos.coords.lation,pos.coords.longitude));
}
功能失败(错误){
drawMap(defaultLatLng);//找不到位置,显示默认地图
}
//查找用户当前位置。缓存该位置5分钟,6秒后超时
navigator.geolocation.getCurrentPosition(成功,失败,{maximumAge:500000,enableHighAccurance:true,超时:6000});
}否则{
drawMap(defaultLatLng);//不支持地理位置,显示默认地图
}
功能绘图图(latlng){
变量myOptions={
缩放:10,
中心:拉特林,
mapTypeId:google.maps.mapTypeId.ROADMAP
};
var map=new google.maps.map(document.getElementById(“地图画布”),myOptions);
//在当前lat/lng地图上添加覆盖图
var marker=new google.maps.marker({
位置:latlng,
地图:地图,
标题:“你好!”
});
}
});
我把js放在html之前,放在html之后

<div data-role="content" class="content">


但是我也试着把它放在头上。

可能你的phonegap项目中没有地理定位插件

cordova插件添加org.apache.cordova.geolocation


尝试在geo调用之前将lat和lng var设置为0

  document.addEventListener("deviceready", onDeviceReady, false);
  function onDeviceReady() { 
    navigator.geolocation.getCurrentPosition(onSuccess, onError, { maximumAge:60000, timeout:5000, enableHighAccuracy:true }); 
  }

  var lat = 0;
  var lng = 0;

  function onSuccess(position) {
    lat += position.coords.latitude
    lng += position.coords.longitude
  }