首页 > 解决方案 > 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>```


标签: androidhtmlapinetbeansmaps

解决方案


推荐阅读