Javascript 为什么我的代码不是';不行吗? var信息窗口, 地点标记=[]; 功能位置搜索(地图、请求){ var-map=map; var service=newgoogle.maps.places.PlacesService(地图); 服务搜索(请求, 功能(结果、状态){ if(status==google.maps.places.PlacesServiceStatus.OK){ var bounds=new google.maps.LatLngBounds(); 对于(变量i=0;i

Javascript 为什么我的代码不是';不行吗? var信息窗口, 地点标记=[]; 功能位置搜索(地图、请求){ var-map=map; var service=newgoogle.maps.places.PlacesService(地图); 服务搜索(请求, 功能(结果、状态){ if(status==google.maps.places.PlacesServiceStatus.OK){ var bounds=new google.maps.LatLngBounds(); 对于(变量i=0;i,javascript,google-maps,google-maps-api-3,geolocation,Javascript,Google Maps,Google Maps Api 3,Geolocation,您需要调用初始化函数,就这样调用它吧 initialize() 确切的问题是什么?i、 e.对代码进行一些描述会很好。它不会显示任何内容:( <html> <head> <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=true&libraries=places"></script> <script> var

您需要调用初始化函数,就这样调用它吧

initialize()


确切的问题是什么?i、 e.对代码进行一些描述会很好。它不会显示任何内容:(
<html>
<head>  
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=true&libraries=places"></script>
<script>      
      var infowindow,
      placemarkers = [];


      function placeSearch(map, request) {
          var map = map;
          var service = new google.maps.places.PlacesService(map);
          service.search(request,

          function (results, status) {
              if (status == google.maps.places.PlacesServiceStatus.OK) {
                  var bounds = new google.maps.LatLngBounds();
                  for (var i = 0; i < results.length; ++i) {
                      bounds.extend(results[i].geometry.location);
                      placemarkers.push(createMarker(results[i].geometry.location,
                      map,
                          'http://labs.google.com/ridefinder/images/mm_20_orange.png',
                      results[i].name,
                      false, {
                          fnc: function () {
                              infowindow.open();
                          }

                      }));
                  }
                  map.fitBounds(bounds);
              }
          });

      }

      function createMarker(latlng, map, icon, content, center, action) {


          var marker = new google.maps.Marker({
              map: map,
              position: latlng,
              content: content
          });
          if (icon) {
              marker.setIcon(icon);
          }

          if (center) {
              map.setCenter(latlng);
          }

          google.maps.event.addListener(marker, 'click', function () {
              infowindow.setContent(this.content);
              infowindow.open(map, this);
          });

          if (action) {
              action.fnc(map, action.args);
          }
          return marker;
      }

      function initialize() {

          var location = new google.maps.LatLng(-33.8665433, 151.1956316),
              map = new google.maps.Map(document.getElementById('map'), {
                  mapTypeId: google.maps.MapTypeId.ROADMAP,
                  center: location,
                  zoom: 15
              });
          infowindow = new google.maps.InfoWindow();
          navigator.geolocation.getCurrentPosition(function (place) {
              createMarker(
              new google.maps.LatLng(place.coords.latitude,
              place.coords.longitude),
              map,
              null,
                  'your current position',
              true, {
                  fnc: placeSearch,
                  args: {
                      radius: 5000,
                      types: ['restaurant'],
                      location: new google.maps.LatLng(place.coords.latitude,
                      place.coords.longitude)
                  }
              });
          });
      }
    </script>
    </head>
    <body>
<div id="map"></div>
    </body>
</html>