Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.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
Api 带标记的地理定位图_Api_Geolocation_Maps - Fatal编程技术网

Api 带标记的地理定位图

Api 带标记的地理定位图,api,geolocation,maps,Api,Geolocation,Maps,我想在我的网站地图api。我已经让地理定位开始工作了,所以它以我的位置为中心。但我还想添加标记。我正在制作一个网站来定位你附近的咖啡店,所以我只希望在谷歌地图中搜索咖啡店时显示的所有标记在加载时显示出来。我在te Maps API网站上搜索过,但找不到我要找的东西 提前谢谢 这是我的代码: <!DOCTYPE html> <html> <head> <title>Geolocation</title> <

我想在我的网站地图api。我已经让地理定位开始工作了,所以它以我的位置为中心。但我还想添加标记。我正在制作一个网站来定位你附近的咖啡店,所以我只希望在谷歌地图中搜索咖啡店时显示的所有标记在加载时显示出来。我在te Maps API网站上搜索过,但找不到我要找的东西

提前谢谢

这是我的代码:

    <!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, {
        height: 100%;
      }

      #map-canvas {
        height: 400px;
        width: 80%;
        margin: 0px;
        padding: 0px
      }
    </style>
    <!--
    Include the maps javascript with sensor=true because this code is using a
    sensor (a GPS locator) to determine the user's location.
    See: https://developers.google.com/maps/documentation/javascript/tutorial#Loading_the_Maps_API
    -->
    <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=AIzaSyAcITWIS3AIRREEJG7oC_BU7f8jVV9MbfE&sensor=false"></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: 9
  };
  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>

您需要使用Google Places API for JS来搜索调用navigator.geolocation.getCurrentPosition返回的纬度/经度位置附近的位置

places API支持按预定义的位置类型进行搜索。他们没有专门的“咖啡馆”,但他们有“咖啡馆”:


谢谢你的回复。是否可以预定义搜索查询?谢谢