谷歌地图API v3不适用于移动浏览器或PhoneGap
Google Maps API v3 not working in mobile browsers or PhoneGap
Google Maps API v3不适用于移动浏览器或PhoneGap,即使我允许所有外部主机
无论是否使用apikey,我都尝试过。
当设备准备就绪(在iDevice(iOS)上)或页面加载(在计算机上)时调用方法loadMapScript()
当我导航到有地图的页面时,我得到消息"Error Loading map"
,这意味着map
是null
我怀疑谷歌检测到我正在使用iOS设备,并限制我使用他们的API,但我没有证据证明这一点。
附言:这适用于所有浏览器!附言:我在iPad的safari中尝试过这个,但它不起作用!但在电脑上工作!附言:刚刚检查过它不适用于任何移动浏览器或phonegap,但适用于所有桌面浏览器:/
如有任何帮助,将不胜感激
代码:
function loadMapScript() {
if($("#googleMaps").length == 0) {
var script = document.createElement("script");
script.type = "text/javascript";
script.id = "googleMaps"
script.src = "http://maps.googleapis.com/maps/api/js?sensor=false&callback=initializeMap&key=HIDDEN";
document.body.appendChild(script);
} else console.log("Error, googleMaps already loaded");
}
function initializeMap(mapOptions) {
console.log("Init Maps");
var myLatlng = new google.maps.LatLng(currentLocation.coords.latitude, currentLocation.coords.longitude);
if(!mapOptions)
mapOptions = {
center: myLatlng,
zoom: 18,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
if(!map)
map = new google.maps.Map(document.getElementById("map_canvas"),
mapOptions);
else {
map.setOptions(mapOptions);
}
updateCurrentLocationMarker();
}
function updateCurrentLocationMarker() {
if(!map) {
return;
}
var myLatlng = new google.maps.LatLng(currentLocation.coords.latitude,
currentLocation.coords.longitude);
if(currentLocationMarker) {
currentLocationMarker.setMap(null);
} else {
currentLocationMarker = new google.maps.Marker({
position: myLatlng,
animation: google.maps.Animation.DROP,
title:"You!"
});
currentLocationMarker.setMap(map);
}
}
function onMapsShow() {
if(!map) {
showToastNow("Error Loading map");
return;
}
}
这段代码怎么样?我根据你的代码创建了代码。我试过我的iPad,结果成功了。
var map, mapOptions, currentLocation, currentLocationMarker;
function loadMapScript() {
var script = document.createElement("script");
script.type = "text/javascript";
script.id = "googleMaps"
script.src = "https://maps.googleapis.com/maps/api/js?sensor=false&callback=initializeMap";
document.body.appendChild(script);
}
function initializeMap(mapOptions) {
var myLatlng = new google.maps.LatLng(currentLocation.coords.latitude, currentLocation.coords.longitude);
var mapOptions = {
center : myLatlng,
zoom : 18,
mapTypeId : google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
updateCurrentLocationMarker();
}
function updateCurrentLocationMarker() {
var myLatlng = new google.maps.LatLng(currentLocation.coords.latitude, currentLocation.coords.longitude);
if (currentLocationMarker) {
currentLocationMarker.setMap(null);
} else {
currentLocationMarker = new google.maps.Marker({
position : myLatlng,
animation : google.maps.Animation.DROP,
title : "You!",
map : map
});
}
}
function onSuccess(position) {
currentLocation = position;
if (!map) {
loadMapScript();
}
}
function onError(error) {
alert('code: ' + error.code + ''n' + 'message: ' + error.message + ''n');
}
function onDeviceReady() {
navigator.geolocation.getCurrentPosition(onSuccess, onError);
}
document.addEventListener("deviceready", onDeviceReady, false);
相关文章:
- 谷歌地图API v3不适用于移动浏览器或PhoneGap
- 在浏览器Cordova/Phonegap中获取页面标题
- Phonegap打开表单提交到Web浏览器上的外部域
- 在Phonegap模拟器/ iPhone中解析JSON与通过浏览器
- Sencha Touch、Apigee JS SDK和Phonegap可以在浏览器中工作,但不能在IOS中工作
- iOS Phonegap网页链接嵌入iframe开放系统浏览器,而不是iframe
- Phonegap:我的Javascript代码适用于浏览器,但不适用于Android模拟器或设备
- 需要从PhoneGap应用程序在不同的浏览器中打开链接
- PhoneGap 在应用程序浏览器加载停止事件问题
- Facebook登录在浏览器中运行良好,但没有;我不能用phonegap在安卓系统上工作
- 如何区分PhoneGap应用程序和本机浏览器
- PhoneGap外部浏览器问题
- 在浏览器中测试PhoneGap+AJAX应用程序
- 让vibrate()在没有PhoneGap的情况下在浏览器中工作
- 安卓系统上的Phonegap 2.7.0;t在默认浏览器中打开外部链接
- Cordova (phonegap):在画布内拖动图像在浏览器中工作良好,但在移动设备中不工作
- Html5要求验证在浏览器上运行良好,但在phonegap应用上就不行
- 用ajax在本地浏览器加载JSON,但不能在PhoneGap应用中加载
- 在设备浏览器中打开InMobi iframe链接(phonegap构建)
- 打开外部浏览器phonegap中的链接