gpt4 book ai didi

ios - 如何在基于 iOS Cordova 的应用程序中的 onDeviceReady 函数后加载 map ?

转载 作者:行者123 更新时间:2023-11-28 21:38:30 24 4
gpt4 key购买 nike

我想在 oDeviceReady 函数之后加载 map 以避免访问 iOS 中的 map 的权限警报,它显示完整的包路径位置,如下所示:(iOS Cordova 3.8.0 版本)

enter image description here

为此我使用了

   <link rel="stylesheet" href="css/jquery.mobile-1.4.5.min.css" />
<script src="cordova.js"></script>
<link href="css/styles.css" rel="stylesheet" type="text/css">
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&libraries=places"></script>
<script src="js/jquery-1.11.1.min.js"></script>
<script src="js/jquery.mobile-1.4.5.min.js"></script>
<script src="js/hashmap.js"></script>

在 head 标签之后:

 </head>
<body onload="onBodyLoad();">//Called onload

在此之后

  function onBodyLoad()
{
document.addEventListener("deviceready", onDeviceReady, false);
}


function onDeviceReady(){
return navigator.geolocation.getCurrentPosition(initialize);
document.addEventListener("backbutton", onBackKeyDown, false);
}

function initialize()
{
geocoder = new google.maps.Geocoder();
if (navigator.geolocation)
{
navigator.geolocation.getCurrentPosition(function (p)
{
LatLng = new google.maps.LatLng(p.coords.latitude, p.coords.longitude);
map = new google.maps.Map(document.getElementById("estimate"), mapOptions);
infowindow = new google.maps.InfoWindow();
marker =new google.maps.Marker({position:LatLng,map:map});
getAddress(p.coords.latitude,p.coords.longitude);

}
}
}

//This line is making to display complete Bundle path loaction
//Where as calling this line to avoid error in onDeviceready, My maps are not loading
// Suggest me where should I call this line of code to avoid this alert
google.maps.event.addDomListener(window, 'load', initialize);


function getAddress(lat, lng)
{
//Code to get address
}

任何人都可以建议我应该在哪里调用下面的电话以避免这种类型的警报;

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

除此警报外,我的代码工作正常...

最佳答案

确保你安装了地理定位插件

cordova plugin add cordova-plugin-geolocation

并将您的代码更改为

function onBodyLoad() {

document.addEventListener("deviceready", onDeviceReady, false);

}


function onDeviceReady(){
navigator.geolocation.getCurrentPosition(initialize);
document.addEventListener("backbutton", onBackKeyDown, false);
}

function initialize(p) {
geocoder = new google.maps.Geocoder();

LatLng = new google.maps.LatLng(p.coords.latitude, p.coords.longitude);
map = new google.maps.Map(document.getElementById("estimate"), mapOptions);
infowindow = new google.maps.InfoWindow();
marker =new google.maps.Marker({position:LatLng,map:map});
getAddress(p.coords.latitude,p.coords.longitude);
}

关于ios - 如何在基于 iOS Cordova 的应用程序中的 onDeviceReady 函数后加载 map ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33012523/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com