比方說,你有模型地圖在你的代碼,水木清華這樣的:在你看來
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 />
謝謝,我可以定義長,緯度在模型雙打?就我所知,小數點就是金錢。 – mans
當然,對它們使用double –