Phonegap Build中的地理位置白屏

时间:2013-11-11 09:23:53

标签: javascript css mobile geolocation dreamweaver

我正在尝试在我的phonegap内容中显示跟踪用户位置的地图。我想尝试使用这个例子,

http://view.jquerymobile.com/master/demos/map-geolocation/

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

<feature name="http://api.phonegap.com/1.0/geolocation"/>
<feature name="http://api.phonegap.com/1.0/network"/> 

到我的config.xml文件。

我得到的是一个没有装载的白色屏幕。

我做错了什么!?!?

谢谢你们!在过去,你们都非常帮助我,这是我完成这个应用程序所需的最后一件事!

提前再次感谢!

我使用的html代码是

<div role="main" class="ui-content" id="map-canvas"></div>

我使用的css代码是

#map-page, #map-canvas { width: 100%; height: 100%; padding: 0; } 

我使用的js代码是

<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> 

我正在把我的js放在我的html之前,就在

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

但我也试过将它放在脑袋里。

2 个答案:

答案 0 :(得分:1)

尝试在地理呼叫之前将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
  }

答案 1 :(得分:0)

您的phonegap项目中可能没有地理位置插件。

http://docs.phonegap.com/en/3.3.0/cordova_geolocation_geolocation.md.html#Geolocation

  

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

相关问题