【问题标题】:Blank space in Geocoding sample app地理编码示例应用程序中的空白
【发布时间】:2015-06-09 15:30:14
【问题描述】:

为什么如果我从https://developers.google.com/maps/documentation/javascript/examples/map-geolocation 复制代码,当我启动应用程序时,我看到所有空格?我使用模拟器 Nexus9。

代码:

<!DOCTYPE html>
<html>
  <head>
    <title>Geolocation</title>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
    <meta charset="utf-8">
    <style>
      html, body, #map-canvas {
        height: 100%;
        margin: 0px;
        padding: 0px
      }
    </style>
    <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&signed_in=true"></script>

    <script>
// Note: This example requires that you consent to location sharing when
// prompted by your browser. If you see a blank space instead of the map, this
// is probably because you have denied permission for location sharing.

var map;

function initialize() {
  var mapOptions = {
    zoom: 6
  };
  map = new google.maps.Map(document.getElementById('map-canvas'),
      mapOptions);

  // Try HTML5 geolocation
  if(navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(function(position) {
      var pos = new google.maps.LatLng(position.coords.latitude,
                                       position.coords.longitude);

      var infowindow = new google.maps.InfoWindow({
        map: map,
        position: pos,
        content: 'Location found using HTML5.'
      });

      map.setCenter(pos);
    }, function() {
      handleNoGeolocation(true);
    });
  } else {
    // Browser doesn't support Geolocation
    handleNoGeolocation(false);
  }
}

function handleNoGeolocation(errorFlag) {
  if (errorFlag) {
    var content = 'Error: The Geolocation service failed.';
  } else {
    var content = 'Error: Your browser doesn\'t support geolocation.';
  }

  var options = {
    map: map,
    position: new google.maps.LatLng(60, 105),
    content: content
  };

  var infowindow = new google.maps.InfoWindow(options);
  map.setCenter(options.position);
}

google.maps.event.addDomListener(window, 'load', initialize);

    </script>
  </head>
  <body>
    <div id="map-canvas"></div>
  </body>
</html>

我在 Eclipse 上使用它。

【问题讨论】:

  • 您是否同意按照说明的要求共享位置信息?
  • LOL @mattfred 我真的很高兴看到船长明显地拯救了一天。即使这不是答案,也喜欢它。
  • 我已添加使用权限 (.ACCESS_COARSE_LOCATION;.ACCESS_FINE_LOCATION;.ACCESS_LOCATION_EXTRA_COMMANDS)。并且在设备上 GPS 已开启
  • blank space.color=='灰色'..?如果是这样,它正在加载,只是很慢,我在模拟器中需要几分钟的时间。
  • 我等了 5 分钟,但没有任何改变。我尝试了三星 Galaxy S4Mini,但我遇到了同样的问题。是的,它是灰色的

标签: javascript android html google-maps


【解决方案1】:

尝试改变这一点:

<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&signed_in=true"></script>

到这里:

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

【讨论】:

    猜你喜欢
    • 2015-07-22
    • 1970-01-01
    • 1970-01-01
    • 2011-04-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多