Javascript Google Maps API在Web浏览器中加载,但不在Android浏览器中加载

Javascript Google Maps API在Web浏览器中加载,但不在Android浏览器中加载,javascript,android,api,google-chrome,maps,Javascript,Android,Api,Google Chrome,Maps,我不知道为什么它不会在我的手机浏览器上运行,但它会在我的电脑浏览器上运行,确切地说是chrome 你们谁能提供反馈 链接到我正在测试的服务器: 54.172.35.180/chat/chatlist.php 功能成功(职位){ var latlng=新的google.maps.latlng(position.coords.latitude,position.coords.longitude); 变量myOptions={ 缩放:15, 中心:拉特林, }; var map=new google

我不知道为什么它不会在我的手机浏览器上运行,但它会在我的电脑浏览器上运行,确切地说是chrome

你们谁能提供反馈

链接到我正在测试的服务器:

54.172.35.180/chat/chatlist.php


功能成功(职位){
var latlng=新的google.maps.latlng(position.coords.latitude,position.coords.longitude);
变量myOptions={
缩放:15,
中心:拉特林,
};
var map=new google.maps.map(document.getElementById(“地图画布”),myOptions);
var marker=new google.maps.marker({
位置:latlng,
地图:地图,
标题:“你在这里!(至少在“+位置.坐标.精度+”米半径内)
});
}
google.maps.event.addDomListener(窗口'load',navigator.geolocation.getCurrentPosition(成功));

我最初只是从API站点复制并粘贴代码,它工作正常,但当我开始提取GPS数据时,它就停止在我的移动设备浏览器上工作。任何帮助都将不胜感激

navigator.geolocation.getCurrentPosition不返回位置。因此,您不能将该结果用作addDomListener(窗口

它的作用是发送一个请求。当该请求准备就绪时,将触发回调。在该回调中,您可以触发函数success()(我将其命名为initialize)


只是为了说明发生了什么。 您仍然可以选择这是否是一个好的继续方式。 请随意重命名,扩展

<script src="http://maps.googleapis.com/maps/api/js"></script>
<script type="text/javascript">
    function initialize(position, accuracy) {
      var latlng = position || new google.maps.LatLng(50.45, 4.45);    // set your own default location.  This gets called if the parameters are left blank.
      var myOptions = {
        zoom: 15,
        center: latlng
      };
      var map = new google.maps.Map(document.getElementById("map-canvas"), myOptions);
      if (position) {
        var marker = new google.maps.Marker({
            position: latlng, 
            map: map, 
            title: "You are here! (at least within a " + accuracy + " meter radius)"
        });
      }
      else {
        // position of the user not found
      }
    }
    function locationFound(position) {
      initialize( 
        new google.maps.LatLng(position.coords.latitude, position.coords.longitude),
        position.coords.accuracy
      );
    }
    function locationNotFound() {
      initialize(null, null);
    }
    function page_loaded() {
      // the page is loaded, we can send a request to search for the location of the user
      navigator.geolocation.getCurrentPosition(locationFound, locationNotFound);
    }
    google.maps.event.addDomListener(window, 'load', page_loaded);
</script>
<style>
#map-canvas {
  width: 500px;
  height: 400px;
}
</style>
<div id="map-canvas"></div>

功能初始化(位置、精度){
var latlng=position | | new google.maps.latlng(50.45,4.45);//设置您自己的默认位置。如果参数为空,则调用此函数。
变量myOptions={
缩放:15,
中心:拉丁
};
var map=new google.maps.map(document.getElementById(“地图画布”),myOptions);
如果(职位){
var marker=new google.maps.marker({
位置:latlng,
地图:地图,
标题:“你在这里!(至少在“+精度+”米半径内)
});
}
否则{
//找不到用户的位置
}
}
功能位置已找到(位置){
初始化(
新的google.maps.LatLng(position.coords.lation,position.coords.longitude),
位置、坐标、精度
);
}
函数locationNotFound(){
初始化(null,null);
}
函数页_已加载(){
//页面加载后,我们可以发送请求以搜索用户的位置
navigator.geolocation.getCurrentPosition(locationFound,locationNotFound);
}
google.maps.event.addDomListener(窗口“加载”,页面加载);
#地图画布{
宽度:500px;
高度:400px;
}
最好先加载地图并设置默认位置。 找到位置后,可以更改中心并设置标记。
现在请注意:如果找不到位置,则需要相当长的时间才能调用locationNotFound

这肯定会解决您的问题。
<script src="http://maps.googleapis.com/maps/api/js"></script>
<script type="text/javascript">
    function initialize(position, accuracy) {
      var latlng = position || new google.maps.LatLng(50.45, 4.45);    // set your own default location.  This gets called if the parameters are left blank.
      var myOptions = {
        zoom: 15,
        center: latlng
      };
      var map = new google.maps.Map(document.getElementById("map-canvas"), myOptions);
      if (position) {
        var marker = new google.maps.Marker({
            position: latlng, 
            map: map, 
            title: "You are here! (at least within a " + accuracy + " meter radius)"
        });
      }
      else {
        // position of the user not found
      }
    }
    function locationFound(position) {
      initialize( 
        new google.maps.LatLng(position.coords.latitude, position.coords.longitude),
        position.coords.accuracy
      );
    }
    function locationNotFound() {
      initialize(null, null);
    }
    function page_loaded() {
      // the page is loaded, we can send a request to search for the location of the user
      navigator.geolocation.getCurrentPosition(locationFound, locationNotFound);
    }
    google.maps.event.addDomListener(window, 'load', page_loaded);
</script>
<style>
#map-canvas {
  width: 500px;
  height: 400px;
}
</style>
<div id="map-canvas"></div>