[英]Geolocation in phonegap not working on emulator
I am newbie to phonegap development. 我是Phonegap开发的新手。 Please help me to getout from the following issue.
请帮助我摆脱以下问题。 I am developing a phonegap application where i have to read the current geolocation coordinates and according to that display the geolocation on map.
我正在开发一个phonegap应用程序,其中我必须读取当前的地理位置坐标,并根据该坐标在地图上显示地理位置。 While i am running my code in the Browser it is working fine, But when i am running the application on emulator or mobile nothing is showing on map, white screen is visible in place of map.
当我在浏览器中运行代码时,它可以正常工作;但是,当我在模拟器或移动设备上运行应用程序时,地图上没有任何显示,可以看到白屏代替地图。
This is my code.Please help me, 这是我的代码。请帮助我,
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style type="text/css">
html { height: 100% }
body { height: 100%; margin: 0; padding: 0 }
#map_canvas { height: 100% width: 100%}
</style>
<script type="text/javascript"
src="http://maps.googleapis.com/maps/api/js?key=AIzaSyA6YvhWQgns2SVExEys8V-WeVfxdQAIqVQ">
</script>
<script type="text/javascript">
var lat = 0;
var long = 0;
infowindow.open(map,marker);
function initGeolocation(){
if( navigator.geolocation){
// Call getCurrentPosition with success and failure callbacks
//navigator.geolocation.getCurrentPosition( success, fail );
navigator.geolocation.getCurrentPosition(success,fail,{enableHighAccuracy:true},{timeout:9000});
}
else{var long = position.coords.longitude;
var lat = position.coords.latitude;
alert("Sorry, your browser does not support geolocation services.");
}
}
function success(position)
{
var long = position.coords.longitude;
var lat = position.coords.latitude;
console.log('Coordinates: ' +position.coords);
console.log('TimeStamp' + position.timestamp);
var myOptions =
{
center: new google.maps.LatLng(lat,long),
zoom: 12,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_canvas"),myOptions);
marker = new google.maps.Marker({
position: new google.maps.LatLng(lat, long),
map: map
});
}
function fail()
{
console.log('error' +error.message);
console.log('code' + error.code);
alert("error");
}
</script>
<div class="divImageHolder">
<a href="menu.html" title="Mouseover Description"><img style="width: 20px; height: 20px; border: 0;" src="http://etc-mysitemyway.s3.amazonaws.com/icons/legacy-previews/icons/green-jelly-icons-media/003210-green-jelly-icon-media-a-media31-back.png" alt="Text Description"></a></div>
</div>
</head>
<body onload="initGeolocation()">
<div id="map_canvas" style="width:100%; height:100%">
</div>
</body>
</html>
Thanks in advance. 提前致谢。
Have you set geolocation in emulator? 您是否在模拟器中设置了地理位置?
Specify the coordinates of position in emulator. 指定模拟器中的位置坐标。
Eclipse -> Open Perspective -> DDMS -> Emulator Control -> Location Controls Eclipse-> Open Perspective-> DDMS->仿真器控件->位置控件
Specify the coordinates of the position and press "Send" . 指定位置的坐标,然后按“发送” 。
referred from [Here] PhoneGap. 引用自[Here] PhoneGap。 Failed to start Geolocation service
无法启动地理定位服务
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.