facebook twitter hatena line email

「Google/Googlemap/js」の版間の差分

提供: 初心者エンジニアの簡易メモ
移動: 案内検索
(ページの作成:「==googlemap貼り付けたい場所に== <div id="map-canvas"></div> ==jsコード== body閉じるタグの直前に。 (34.804618851, 135.345302589)の所には緯度...」)
 
行4: 行4:
 
==jsコード==
 
==jsコード==
 
body閉じるタグの直前に。
 
body閉じるタグの直前に。
(34.804618851, 135.345302589)の所には緯度経度を入力。
+
<script src="https://maps.googleapis.com/maps/api/js?key=[apikey]"></script>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
+
<style>
<style>
+
#map-canvas {
#map-canvas {
+
    width: 700px;
height: 400px;
+
    height: 400px;
margin: 0px;
+
}
padding: 0px
+
</style>
}
+
<script type="text/javascript">
</style>
+
var map = new google.maps.Map(document.getElementById('map-canvas'), {
<script type="text/javascript">
+
     center: new google.maps.LatLng(34.7019399, 135.51002519999997),
google.maps.event.addDomListener(window, 'load', function() {
+
     zoom: 15
  var map = document.getElementById("map-canvas");
+
});
  var options = {
+
var marker = new google.maps.Marker({
    zoom: 17,
+
    position: new google.maps.LatLng(34.7019399, 135.51002519999997),
     center: new google.maps.LatLng(34.804618851, 135.345302589),
+
    map: map
     mapTypeId: google.maps.MapTypeId.ROADMAP
+
});
  };
+
var infoWindow = new google.maps.InfoWindow({
  var map = new google.maps.Map(map, options);
+
    content: '<div class="sample">大阪</div>'
  var marker = new google.maps.Marker({
+
});
      position: new google.maps.LatLng(34.804618851, 135.345302589),
+
marker.addListener('click', function() {
      map: map,
+
    infoWindow.open(map, marker);
      title: "pin表示"
+
});
  });
+
var marker2 = new google.maps.Marker({
});
+
    position: new google.maps.LatLng(34.804618851, 135.345302589),
</script>
+
    map: map
 +
});
 +
infoWindow2 = new google.maps.InfoWindow({
 +
    content: '<div class="sample">兵庫</div>'
 +
});
 +
marker2.addListener('click', function() {
 +
    infoWindow2.open(map, marker2);
 +
});
 +
</script>

2016年8月4日 (木) 17:22時点における版

googlemap貼り付けたい場所に

jsコード

body閉じるタグの直前に。 <script src="https://maps.googleapis.com/maps/api/js?key=[apikey]"></script> <style>

  1. map-canvas {
   width: 700px;
   height: 400px;

} </style> <script type="text/javascript"> var map = new google.maps.Map(document.getElementById('map-canvas'), {

   center: new google.maps.LatLng(34.7019399, 135.51002519999997),
   zoom: 15

}); var marker = new google.maps.Marker({

   position: new google.maps.LatLng(34.7019399, 135.51002519999997),
   map: map

}); var infoWindow = new google.maps.InfoWindow({

content: '
大阪
'

}); marker.addListener('click', function() {

   infoWindow.open(map, marker);

}); var marker2 = new google.maps.Marker({

   position: new google.maps.LatLng(34.804618851, 135.345302589),
   map: map

}); infoWindow2 = new google.maps.InfoWindow({

content: '
兵庫
'

}); marker2.addListener('click', function() {

   infoWindow2.open(map, marker2);

}); </script>