Adding infowindow to custom Google Streetview

后端 未结 1 1930
梦毁少年i
梦毁少年i 2021-01-26 11:11

Please help me add an InfoWindow to this custom google street view. http://jsfiddle.net/geocodezip/7mh5ac28/2/

Heres the code i\'m tring to add to integrate the infomar

相关标签:
1条回答
  • 2021-01-26 11:12

    You have a typo in your code. bankMarker should be cafeMarker.

    proof of concept fiddle

    code snippet:

    var geocoder;
    var map;
    
    function initialize() {
      var fenway = new google.maps.LatLng(34.9355, -107.539254);
    
      var panoOptions = {
        position: fenway,
        addressControlOptions: {
          position: google.maps.ControlPosition.BOTTOM_CENTER
        },
        linksControl: false,
        panControl: false,
        zoomControlOptions: {
          style: google.maps.ZoomControlStyle.SMALL
        },
        enableCloseButton: false
      };
    
      var panorama = new google.maps.StreetViewPanorama(
        document.getElementById('map-canvas'), panoOptions);
    
      var cafe = new google.maps.LatLng(34.935196, -107.539546);
    
      var cafeMarker = new google.maps.Marker({
        position: cafe,
        map: panorama,
        icon: 'http://chart.apis.google.com/chart?chst=d_map_pin_icon&chld=cafe|FFFF00',
        title: 'Cafe'
      });
    
      var contentString = '<div id="content">' +
        '<div id="siteNotice">' +
        '</div>' +
        '<h1 id="firstHeading" class="firstHeading">Uluru</h1>' +
        '<div id="bodyContent">' +
        '<p>Attribution: <a href="https://en.wikipedia.org/w/index.php?title=Uluru&oldid=297882194">' +
        'Uluru</a> ' +
        '(last visited June 22, 2009).</p>' +
        '</div>' +
        '</div>';
    
      var infowindow = new google.maps.InfoWindow({
        content: contentString
      });
    
    
      google.maps.event.addListener(cafeMarker, 'click', function() {
        infowindow.open(panorama, cafeMarker);
      });
    
      // Set up the map ======================================================================
      var myOptions = {
        zoom: 15,
        center: cafe
      };
      map = new google.maps.Map(document.getElementById('map_canvas'),
        myOptions);
      var cafeMarkerMap = new google.maps.Marker({
        position: cafe,
        map: map,
        icon: 'http://chart.apis.google.com/chart?chst=d_map_pin_icon&chld=cafe|FFFF00',
        title: 'Cafe'
      });
      var panoMarker = new google.maps.Marker({
        position: panorama.getPosition(),
        map: map,
        icon: {
          url: 'https://maps.gstatic.com/intl/en_us/mapfiles/markers2/measle.png',
          size: new google.maps.Size(7, 7),
          anchor: new google.maps.Point(3.5, 3.5)
        },
        title: 'Pano'
      });
    
      document.getElementById('info').innerHTML = google.maps.geometry.spherical.computeDistanceBetween(panorama.getPosition(), cafe).toFixed(2) + " meters";
      var heading = google.maps.geometry.spherical.computeHeading(panorama.getPosition(), cafe);
    
      // alert(data.location.latLng+":"+myLatLng+":"+heading);
      panorama.setPov({
        heading: heading,
        pitch: 0,
        zoom: 1
      });
      google.maps.event.addListener(map, 'click', function(evt) {
        document.getElementById('info').innerHTML = evt.latLng.toUrlValue(6);
      });
    }
    google.maps.event.addDomListener(window, 'load', initialize);
    html,
    body,
    #map-canvas,
    #map_canvas {
      height: 500px;
      width: 500px;
      margin: 0px;
      padding: 0px
    }
    <script src="https://maps.googleapis.com/maps/api/js?libraries=geometry,places"></script>
    <div id="map-canvas" style="border: 2px solid #3872ac;"></div>
    <div id="map_canvas" style="border: 2px solid #3872ac;"></div>
    <div id="info"></div>

    0 讨论(0)
提交回复
热议问题