2017-04-15 22 views
0

HTML5の簡単なランディングページでうっとりしていました。私もここで答えを探しました。私はマニュアルと行わマップでgettedたHTML5のGoogleマップのJavaScript

<!-- Main JS File --> 
    <script src="js/main-multi-scroll.js"></script> 

<!-- +++ START - Contact Right +++ --> 
      <div class="ms-section" id="right5"> 

       <div class="map-info split-section"> 

        <div id="map"></div> 

       </div> 

      </div> 
      <!-- +++ END - Contact Right +++ --> 

     </div> 
     <!-- CLOSE - RIGHT PART --> 

と、この: 問題は私のHTMLページが下部にある連絡先のモジュールを持っているということであるとして、それはメインページのコードに含ま.jsファイルは、以下に挙げる:

// When the window has finished loading create our google map below 
google.maps.event.addDomListener(window, 'load', init); 
google.maps.event.addDomListener(window, 'resize', init); 

function init() { 

// Basic options for a simple Google Map 
<script async defer 
src="https://maps.googleapis.com/maps/api/js?key=KEYVALUE&callback=initMap"> 
     </script> 
// The latitude and longitude to center the map (always required) 
var center = new google.maps.LatLng(55.76197976545492,37.68354535102844); 
// For more options see: https://developers.google.com/maps/documentation/javascript/reference#MapOptions 
var isDraggable = $(document).width() > 1024 ? true : false; // If document (your website) is wider than 1024px, isDraggable = true, else isDraggable = false 

// For more options see: https://developers.google.com/maps/documentation/javascript/reference#MapOptions 
var mapOptions = { 
    // How zoomed in you want the map to start at (always required) 
    zoom: 18, 
    scrollwheel: false, 
    draggable: isDraggable, 
    center: center, 
    streetViewControl: true, 
    mapTypeControl: true, 

    zoomControlOptions: { 
    position: google.maps.ControlPosition.LEFT_TOP 
}, 

streetViewControlOptions: { 
    position: google.maps.ControlPosition.LEFT_TOP 
}, 

    // How you would like to style the map. 
    // This is where you would paste any style found on Snazzy Maps. 


    styles: [ 
{ 
    "featureType": "administrative.province", 
    "elementType": "all", 
    "stylers": [ 
     { 
      "visibility": "off" 
     } 
    ] 
}, 
{ 
    "featureType": "landscape", 
    "elementType": "all", 
    "stylers": [ 
     { 
      "saturation": -100 
     }, 
     { 
      "lightness": 65 
     }, 
     { 
      "visibility": "on" 
     } 
    ] 
}, 
{ 
    "featureType": "poi", 
    "elementType": "all", 
    "stylers": [ 
     { 
      "saturation": -100 
     }, 
     { 
      "lightness": 51 
     }, 
     { 
      "visibility": "simplified" 
     } 
    ] 
}, 
{ 
    "featureType": "road.highway", 
    "elementType": "all", 
    "stylers": [ 
     { 
      "saturation": -100 
     }, 
     { 
      "visibility": "simplified" 
     } 
    ] 
}, 
{ 
    "featureType": "road.arterial", 
    "elementType": "all", 
    "stylers": [ 
     { 
      "saturation": -100 
     }, 
     { 
      "lightness": 30 
     }, 
     { 
      "visibility": "on" 
     } 
    ] 
}, 
{ 
    "featureType": "road.local", 
    "elementType": "all", 
    "stylers": [ 
     { 
      "saturation": -100 
     }, 
     { 
      "lightness": 40 
     }, 
     { 
      "visibility": "on" 
     } 
    ] 
}, 
{ 
    "featureType": "transit", 
    "elementType": "all", 
    "stylers": [ 
     { 
      "saturation": -100 
     }, 
     { 
      "visibility": "simplified" 
     } 
    ] 
}, 
{ 
    "featureType": "water", 
    "elementType": "geometry", 
    "stylers": [ 
     { 
      "hue": "#006bff" 
     }, 
     { 
      "lightness": "-10" 
     }, 
     { 
      "saturation": "-92" 
     }, 
     { 
      "gamma": "0.37" 
     } 
    ] 
}, 
{ 
    "featureType": "water", 
    "elementType": "geometry.fill", 
    "stylers": [ 
     { 
      "color": "#323a45" 
     } 
    ] 
}, 
{ 
    "featureType": "water", 
    "elementType": "labels", 
    "stylers": [ 
     { 
      "visibility": "on" 
     }, 
     { 
      "lightness": -25 
     }, 
     { 
      "saturation": -100 
     } 
    ] 
}, 
{ 
    "featureType": "water", 
    "elementType": "labels.text", 
    "stylers": [ 
     { 
      "color": "#4f5256" 
     } 
    ] 
}, 
{ 
    "featureType": "water", 
    "elementType": "labels.text.stroke", 
    "stylers": [ 
     { 
      "color": "#ffffff" 
     } 
    ] 
} 
] 
    }; 
var map = new google.maps.Map(document.getElementById('map'), mapOptions, center); 

var locations = [ 
    ['<h6>ул. Радио, д. 24, к.1</h6><p>БЦ Яуза Тауэр<br><i class="fa fa-coffee"></i> Приходите к нам в гости!</p>', 55.76197976545492,37.68354535102844, 1], 
]; 

var infowindow = new google.maps.InfoWindow(); 

var marker, i; 
var image = 'img/v-logo-map.png'; 

for (i = 0; i < locations.length; i++) { 
    marker = new google.maps.Marker({ 
     position: new google.maps.LatLng(locations[i][1], locations[i][2]), 
     map: map, 
     icon: image 
    }); 

    google.maps.event.addListener(marker, 'click', (function(marker, i) { 
     return function() { 
      infowindow.setContent(locations[i][0]); 
      infowindow.open(map, marker); 
     }; 
    })(marker, i)); 
} 

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

} 

を私はマニュアルとGoogleマップによってすべてをしたきた問題は、私のウェブサイト上で表示されません。私もGoogle Maps APIの認証要求を指定し、生成してコードに挿入しましたが、それはまったく役に立たなかったのです。

あなたが近づいをチェックしたい場合 - http://vernizone.ru

はあなたが私はそれを解決するのに役立つことを願って - 私は、このサイトの製品バージョンで行かなければなりません。

+0

に役立ちますか?問題を示す[mcve]を入力してください。 – geocodezip

答えて

0

EDIT:コードに必要な変更を加えました。

map.jsファイルから次<script>タグを削除し、</body>タグ

<script async defer src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=init&v=3" type="text/javascript"></script> 

前に、インデックスページの上に置くと、あなたのmap.jsファイルが同じ(ちょうどマイナスつまり上記タグ)でなければなりません

// When the window has finished loading create our google map below 
    google.maps.event.addDomListener(window, 'load', init); 
    google.maps.event.addDomListener(window, 'resize', init); 

    function init() { 

    // Basic options for a simple Google Map 
    // The latitude and longitude to center the map (always required) 
    var center = new google.maps.LatLng(55.76197976545492,37.68354535102844); 
    // For more options see: https://developers.google.com/maps/documentation/javascript/reference#MapOptions 
    var isDraggable = $(document).width() > 1024 ? true : false; // If document (your website) is wider than 1024px, isDraggable = true, else isDraggable = false 

    // For more options see: https://developers.google.com/maps/documentation/javascript/reference#MapOptions 
    var mapOptions = { 
     // How zoomed in you want the map to start at (always required) 
     zoom: 18, 
     scrollwheel: false, 
     draggable: isDraggable, 
     center: center, 
     streetViewControl: true, 
     mapTypeControl: true, 

     zoomControlOptions: { 
     position: google.maps.ControlPosition.LEFT_TOP 
    }, 

    streetViewControlOptions: { 
     position: google.maps.ControlPosition.LEFT_TOP 
    }, 

     // How you would like to style the map. 
     // This is where you would paste any style found on Snazzy Maps. 
     styles: [ 
{ 
    "featureType": "administrative.province", 
    "elementType": "all", 
    "stylers": [ 
     { 
      "visibility": "off" 
     } 
    ] 
}, 
{ 
    "featureType": "landscape", 
    "elementType": "all", 
    "stylers": [ 
     { 
      "saturation": -100 
     }, 
     { 
      "lightness": 65 
     }, 
     { 
      "visibility": "on" 
     } 
    ] 
}, 
{ 
    "featureType": "poi", 
    "elementType": "all", 
    "stylers": [ 
     { 
      "saturation": -100 
     }, 
     { 
      "lightness": 51 
     }, 
     { 
      "visibility": "simplified" 
     } 
    ] 
}, 
{ 
    "featureType": "road.highway", 
    "elementType": "all", 
    "stylers": [ 
     { 
      "saturation": -100 
     }, 
     { 
      "visibility": "simplified" 
     } 
    ] 
}, 
{ 
    "featureType": "road.arterial", 
    "elementType": "all", 
    "stylers": [ 
     { 
      "saturation": -100 
     }, 
     { 
      "lightness": 30 
     }, 
     { 
      "visibility": "on" 
     } 
    ] 
}, 
{ 
    "featureType": "road.local", 
    "elementType": "all", 
    "stylers": [ 
     { 
      "saturation": -100 
     }, 
     { 
      "lightness": 40 
     }, 
     { 
      "visibility": "on" 
     } 
    ] 
}, 
{ 
    "featureType": "transit", 
    "elementType": "all", 
    "stylers": [ 
     { 
      "saturation": -100 
     }, 
     { 
      "visibility": "simplified" 
     } 
    ] 
}, 
{ 
    "featureType": "water", 
    "elementType": "geometry", 
    "stylers": [ 
     { 
      "hue": "#006bff" 
     }, 
     { 
      "lightness": "-10" 
     }, 
     { 
      "saturation": "-92" 
     }, 
     { 
      "gamma": "0.37" 
     } 
    ] 
}, 
{ 
    "featureType": "water", 
    "elementType": "geometry.fill", 
    "stylers": [ 
     { 
      "color": "#323a45" 
     } 
    ] 
}, 
{ 
    "featureType": "water", 
    "elementType": "labels", 
    "stylers": [ 
     { 
      "visibility": "on" 
     }, 
     { 
      "lightness": -25 
     }, 
     { 
      "saturation": -100 
     } 
    ] 
}, 
{ 
    "featureType": "water", 
    "elementType": "labels.text", 
    "stylers": [ 
     { 
      "color": "#4f5256" 
     } 
    ] 
}, 
{ 
    "featureType": "water", 
    "elementType": "labels.text.stroke", 
    "stylers": [ 
     { 
      "color": "#ffffff" 
     } 
    ] 
} 
] 
    }; 

    var map = new google.maps.Map(document.getElementById('map'), mapOptions, center); 

    var locations = [ 
     ['<h6>ул. Радио, д. 24, к.1</h6><p>БЦ Яуза Тауэр<br><i class="fa fa-coffee"></i> Приходите к нам в гости!</p>', 55.76197976545492,37.68354535102844, 1], 
    ]; 

    var infowindow = new google.maps.InfoWindow(); 

    var marker, i; 
    var image = 'img/v-logo-map.png'; 

    for (i = 0; i < locations.length; i++) { 
     marker = new google.maps.Marker({ 
      position: new google.maps.LatLng(locations[i][1], locations[i][2]), 
      map: map, 
      icon: image 
     }); 

     google.maps.event.addListener(marker, 'click', (function(marker, i) { 
      return function() { 
       infowindow.setContent(locations[i][0]); 
       infowindow.open(map, marker); 
      }; 
     })(marker, i)); 
    } 

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

} 

希望これはどのように地図のdivのサイズを設定している

+0

Heya、私はコールバック= initMapを追加しました - それは私を助けませんでした –

+0

私はまた、このコードがなくても、それは例であったように試してみました - それはまた動作しません –

+0

私は私が見つけた解決策、それが助けられたかどうか試してみてください – SpaceBaar

関連する問題