2012-06-10 23 views
0

我是Google地圖的新手,我需要將Google Map視圖保存到數據庫中(long + lat + zoom)。 我知道MVC,但我不知道如何在視圖上顯示Google Map視圖信息(long + Lat + zoom)。在mvc中保存和檢索GoogleMap視圖到sql

另外,當我從數據庫中檢索數據時,如何在剃鬚刀視圖中更改Google地圖的視圖?

任何幫助,包括一些參考閱讀非常讚賞。

我正在考慮這樣做的一種方式是創建三個隱藏的輸入,當用戶使用地圖進行遊戲並更改Google Map視圖時,其值會發生變化。但我不知道如何使用JS和Google Map來做到這一點。

回答

2

比方說,你有模型地圖在你的代碼,水木清華這樣的:在你看來

public class MapModel 
{ 
    /// <summary> 
    /// Lattitude on map 
    /// </summary> 
    public decimal Lat { get; set; } 

    /// <summary> 
    /// Longtidute on map 
    /// </summary> 
    public decimal Lon { get; set; } 

    /// <summary> 
    /// Map zoom level 
    /// </summary> 
    public int Zoom { get; set; } 
} 

將谷歌地圖腳本:

<head runat="server"> 
<title>Index</title> 
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script> 

    function initialize() 
    { 
    var mapDiv = document.getElementById('MapDiv'); 
    var map = new google.maps.Map(mapDiv, { 
     center: new google.maps.LatLng(<%= Model.Lat %>, <%= Model.Lon %>), 
     zoom: <%= Model.Zoom %>, 
     mapTypeId: google.maps.MapTypeId.ROADMAP 
    }); 

    google.maps.event.addListener(map, 'click', function(event) 
    { 
     // Puts coordinates to form (then pass to DB using Ajax, etc) 
     document.getElementById("Lat").value = event.latLng.lat(); 
     document.getElementById("Lon").value = event.latLng.lng(); 
     document.getElementById("Zoom").value = map.getZoom(); 
    }); 
    } 
    google.maps.event.addDomListener(window, 'load', initialize); 


<div id="MapDiv" style="width: 500px; height: 500px"></div> 
<input type="text" id="Lat" value="0" /><br /> 
<input type="text" id="Lon" value="0" /><br /> 
<input type="text" id="Zoom" value="0" /><br /> 
+0

謝謝,我可以定義長,緯度在模型雙打?就我所知,小數點就是金錢。 – mans

+0

當然,對它們使用double –

相關問題