简体   繁体   English

Phonegap构建中的地理位置白屏

[英]Geolocation White Screen in Phonegap Build

I am trying to show a map tracking a users location in my phonegap build. 我正在尝试显示在我的phonegap版本中跟踪用户位置的地图。 I am trying to use this example, 我正在尝试使用此示例,

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

And i have added the html css and js to my app and added 而且我已经将html css和js添加到我的应用程序中并添加了

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

to my config.xml file. 到我的config.xml文件。

all i get is a white screen with nothing loading. 我所得到的只是一个没有加载任何东西的白色屏幕。

What am i doing wrong!?!? 我究竟做错了什么!?!?

Thanks guys! 多谢你们! You have all helped me out very much in the past and this is the last thing i need to finish this app! 过去,你们都对我有很大帮助,这是我需要完成此应用程序的最后一件事!

Thanks again in advance! 再次感谢!

my html code i use is 我使用的html代码是

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

my css code i use is 我使用的CSS代码是

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

my js code i use is 我使用的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> 

and i am putting my js right before my html , right after 我把我的js放在我的html之前

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

but i have tried placing it in the head as well. 但我也尝试过将其放在头部。

Try setting the lat and lng var to 0 prior to the geo call. 尝试在地理调用之前将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
  }

Probably you don't have the geolocation plugin in your phonegap project. 可能您的phonegap项目中没有地理位置插件。

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM