2017-03-08 4 views
0

私は自分の見解でGoogleマップを表示しようとしています。ここに私のコードです:mshc2を使用してcshtmlでdiv要素のIDを書き込む

$(document).ready(function() { 
    Initialize(); 
    function Initialize() { 
     google.maps.visualRefresh = true; 
     var Tunisie = new google.maps.LatLng(36.81881, 10.16596); 
     var mapOptions = { 
      zoom: 8, 
      center: Tunisie, 
      mapTypeId: google.maps.MapTypeId.G_NORMAL_MAP 
     }; 
     var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions); 
     var myLatlng = new google.maps.LatLng(36.81881, 10.16596); 
     var marker = new google.maps.Marker({ 
      position: myLatlng, 
      map: map, 
      title: 'Tate Gallery' 
     }); 
     marker.setIcon('http://maps.google.com/mapfiles/ms/icons/green-dot.png') 
     google.maps.event.addListener(marker, 'click', function() { 
      infowindow.open(map, marker); 
     }); 
    } 
}); 

現在のところ、このjavascriptはインデックスビューに置かれています。私はmap_canvas idのdiv要素にこのjavascriptを適用したいと思います。私はidがmap_canvasのdiv要素をこのcshtmlで使用していますが、何も表示されません。

div要素はどこで使用できますか?あなたのを交換する必要があり

+0

Googleを参照していますか?

+0

私はこれを使用します: div要素で何も間違っていないことを示しています....このjavascriptで何が間違っていますか? –

答えて

0

<script src="maps.google.com/maps/api/js?sensor=true"; type="text/javascript"></script> 

と:

<script src="http://maps.googleapis.com/maps/api/js?sensor=true" ; type="text/javascript"></script> 

EDIT:

インデックス:

これは私がテストプロジェクトを持っている正確なコードです。 cshtml:

<style> 
#map_canvas{ 
     margin-top: 50px; 
     height: 250px; 
    } 
</style> 

@section Scripts{ 
<script src="http://maps.googleapis.com/maps/api/js?sensor=true" ; type="text/javascript"></script> 

<script type="text/javascript"> 
    $(document).ready(function() { 
     Initialize(); 
     function Initialize() { 
      google.maps.visualRefresh = true; 
      var Tunisie = new google.maps.LatLng(36.81881, 10.16596); 
      var mapOptions = { 
       zoom: 8, 
       center: Tunisie, 
       mapTypeId: google.maps.MapTypeId.G_NORMAL_MAP 
      }; 
      var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions); 
      var myLatlng = new google.maps.LatLng(36.81881, 10.16596); 
      var marker = new google.maps.Marker({ 
       position: myLatlng, 
       map: map, 
       title: 'Tate Gallery' 
      }); 
      marker.setIcon('http://maps.google.com/mapfiles/ms/icons/green-dot.png') 
      google.maps.event.addListener(marker, 'click', function() { 
       infowindow.open(map, marker); 
      }); 
     } 
    }); 
</script> 
} 
+0

これも試してみましたが、Google Maps APIエラー:MissingKeyMapErrorが表示されます。 私はこの使用: ます。 それはグーグルマップは未定義を示しています。 私は絶望的です。 –

+0

には、http:// –

+0

が含まれています。はい、これは...これは誤植です...ごめんなさい –