Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/382.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何获取用户';使用Google Maps API v3从iPhone上获取的位置?_Javascript_Iphone_Google Maps_Geolocation_Google Maps Api 3 - Fatal编程技术网

Javascript 如何获取用户';使用Google Maps API v3从iPhone上获取的位置?

Javascript 如何获取用户';使用Google Maps API v3从iPhone上获取的位置?,javascript,iphone,google-maps,geolocation,google-maps-api-3,Javascript,Iphone,Google Maps,Geolocation,Google Maps Api 3,我想在iPhone上制作一张谷歌地图,并在用户第一次打开网站时显示其位置 但是我在谷歌地图V3API上找不到这个方法。所以我想也许iPhone有这个功能。是吗?您可能想使用iPhone上Safari支持的 使用Geolocation API中的位置在Google地图上绘制一个点,将如下所示: if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(function(position) { va

我想在iPhone上制作一张谷歌地图,并在用户第一次打开网站时显示其位置

但是我在谷歌地图V3API上找不到这个方法。所以我想也许iPhone有这个功能。是吗?

您可能想使用iPhone上Safari支持的

使用Geolocation API中的位置在Google地图上绘制一个点,将如下所示:

if (navigator.geolocation) { 
  navigator.geolocation.getCurrentPosition(function(position) {  

    var point = new google.maps.LatLng(position.coords.latitude, 
                                       position.coords.longitude);

    // Initialize the Google Maps API v3
    var map = new google.maps.Map(document.getElementById('map'), {
      zoom: 15,
      center: point,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    });

    // Place a marker
    new google.maps.Marker({
      position: point,
      map: map
    });
  }); 
} 
else {
  alert('W3C Geolocation API is not available');
} 
确保您的web文档中包含Google Maps API v3:

<script src="http://maps.google.com/maps/api/js?sensor=true" 
        type="text/javascript"></script>

。。。并且您有地图画布的占位符:

<div id="map" style="width: 500px; height: 400px;"></div>

您可能需要使用iPhone上Safari支持的

使用Geolocation API中的位置在Google地图上绘制一个点,将如下所示:

if (navigator.geolocation) { 
  navigator.geolocation.getCurrentPosition(function(position) {  

    var point = new google.maps.LatLng(position.coords.latitude, 
                                       position.coords.longitude);

    // Initialize the Google Maps API v3
    var map = new google.maps.Map(document.getElementById('map'), {
      zoom: 15,
      center: point,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    });

    // Place a marker
    new google.maps.Marker({
      position: point,
      map: map
    });
  }); 
} 
else {
  alert('W3C Geolocation API is not available');
} 
确保您的web文档中包含Google Maps API v3:

<script src="http://maps.google.com/maps/api/js?sensor=true" 
        type="text/javascript"></script>

。。。并且您有地图画布的占位符:

<div id="map" style="width: 500px; height: 400px;"></div>


要添加一件事——如果要获取用户的位置,则在加载地图api时需要传递sensor=true:@Mark:Oops您是对的。谷歌确实强调了这一点。修正了我的答案。@Kandhasamy:你有没有给GPS一个好的修正时间?需要补充一点——如果你得到了用户的位置,那么在加载地图api时你需要通过sensor=true:@Mark:Oops你是对的。谷歌确实强调了这一点。修正了我的答案。@Kandhasamy:你有没有给GPS一个好的修正时间?