android - HTML Google Maps API 正在桌面浏览器上加载,但不在 Android 上
问题描述
首先我想和你分享我的问题!第一个:那是代码...我在使用浏览器时获得了坐标,但是当我尝试在我的 Android 设备上获得相同的信息时,它什么也不做,甚至不显示错误...我' m 使用 Netbeans 8.2 对 HTML 文件进行编码。
如果我尝试加载地图(使用谷歌地图上的共享选项,地图加载得很好,但它似乎无法获取我的坐标......此外,它确实询问我是否想在页。
<script src="https://maps.googleapis.com/maps/api/js?key=YES_I_HAVE_A_KEY&callback=initMap">
</script>
<script>
function showPosition() {
if(navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showMap, showError);
} else {
alert("Lo sentimos, su navegador no soporta geolocalizacion.");
}
}
// Define callback function for successful attempt
function showMap(position) {
// Get location data
lat = position.coords.latitude;
long = position.coords.longitude;
var latlong = new google.maps.LatLng(lat, long);
var myOptions = {
center: latlong,
zoom: 16,
mapTypeControl: true,
navigationControlOptions: {
style:google.maps.NavigationControlStyle.SMALL
}
}
var map = new google.maps.Map(document.getElementById("embedMap"), myOptions);
var marker = new google.maps.Marker({ position:latlong, map:map, title:"¡Estas aqui!" });
}
// Define callback function for failed attempt
function showError(error) {
if(error.code == 1) {
result.innerHTML = "Decidiste no mostrar tu ubicacion :(";
} else if(error.code == 2) {
result.innerHTML = "Tu internet esta fallando, o el servicio GIS no esta funcionando.";
} else if(error.code == 3) {
result.innerHTML = "Tu solicitud para ubicarte no ha podido ser completada.";
} else {
result.innerHTML = "La geolocalizacion ha fallado por un error desconocido.";
}
}
</script>
</head>
<body>
<button type="button" onclick="showPosition();">Mostrar mi ubicacion en Google Maps</button>
<div id="embedMap" style="width: 600px; height: 500px;">
<!--Google map will be embedded here-->
</div>
</body>
</html>```
解决方案
推荐阅读
- qt - 弹出窗口顶部的 QML 粒子系统
- ansible - Ansible:模块执行期间意外失败“find()正好需要2个参数(3个给定)”
- tsql - 如果相关的 t-sql 将字符串转换为 int
- php - laravel 验证不起作用
- javascript - 如何重定向干净的网址
- angular - 如何让 firebase serve 在 Angular 项目中接管 ng serve 以将本地开发列入白名单?
- python - 无法运行 Poincare 嵌入示例以获取分层表示
- wordpress - WordPress 站点图像随处加载,但在客户的本地办公室 PC 上
- c# - 如何调试 WPF NET 应用程序以检测锁等
- ios - WKWebView 获取 Javascript 错误