如何在 iOS 基于 Cordova 的应用程序中的 onDeviceReady 函数后加载地图?
how to load Maps after onDeviceReady function in iOS Cordova based app?
我想在 oDeviceReady 函数之后加载地图以避免在 iOS 中访问地图的权限警报,它显示完整的包路径位置,如下所示:(iOS Cordova 3.8.0 版本)
为此我使用了
<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>
<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);
除此警报外,我的代码运行良好...
首先使用命令提示符(cmd)添加这个插件
cordova插件添加org.apache.cordova.geolocation
<div id="map" style="width:100%; height:500px;"></div>
<script>
$(document).ready(function () {
var geocoder;
var map;
function initialize()
{
geocoder = new google.maps.Geocoder();
var mapOptions = {
zoom: 12
};
map = new google.maps.Map(document.getElementById('map'), mapOptions);
codeAddress();
}
google.maps.event.addDomListener(window, 'load', initialize);
if (navigator.geolocation)
{
navigator.geolocation.getCurrentPosition(function (position) {
initialLocation = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
map.setCenter(initialLocation);
});
}
});
</script>
确保你安装了地理定位插件
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);
}
我想在 oDeviceReady 函数之后加载地图以避免在 iOS 中访问地图的权限警报,它显示完整的包路径位置,如下所示:(iOS Cordova 3.8.0 版本)
为此我使用了
<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>
<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);
除此警报外,我的代码运行良好...
首先使用命令提示符(cmd)添加这个插件
cordova插件添加org.apache.cordova.geolocation
<div id="map" style="width:100%; height:500px;"></div>
<script>
$(document).ready(function () {
var geocoder;
var map;
function initialize()
{
geocoder = new google.maps.Geocoder();
var mapOptions = {
zoom: 12
};
map = new google.maps.Map(document.getElementById('map'), mapOptions);
codeAddress();
}
google.maps.event.addDomListener(window, 'load', initialize);
if (navigator.geolocation)
{
navigator.geolocation.getCurrentPosition(function (position) {
initialLocation = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
map.setCenter(initialLocation);
});
}
});
</script>
确保你安装了地理定位插件
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);
}