C# 在asp.net中绘制点与点之间的路径google map
我对嵌入在c#中的谷歌地图脚本有一个问题。我想画点之间的路径。我试了一些样品,但不行。现在我可以展示我的观点了 我的代码如下C# 在asp.net中绘制点与点之间的路径google map,c#,javascript,asp.net,google-maps,C#,Javascript,Asp.net,Google Maps,我对嵌入在c#中的谷歌地图脚本有一个问题。我想画点之间的路径。我试了一些样品,但不行。现在我可以展示我的观点了 我的代码如下 private void BuildScript(DataTable tbl) { foreach (DataRow r in tbl.Rows) { Latitude = r["Latitude"].ToString(); Longitude = r["Longitude"]
private void BuildScript(DataTable tbl)
{
foreach (DataRow r in tbl.Rows)
{
Latitude = r["Latitude"].ToString();
Longitude = r["Longitude"].ToString();
Locations += Environment.NewLine + " map.addOverlay(new GMarker(new GLatLng(" + Latitude + "," + Longitude + "))); ";
i++;
}
js.Text = @"<script type='text/javascript'>
function initialize() {
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById('map_canvas'));
map.setCenter(new GLatLng("+Latitude+","+Longitude+ @"), 10);
" + Locations + @"
map.openInfoWindow(map.getCenter(), document.createTextNode("+Latitude+@"));
map.setUIToDefault();
}
}
</script> ";
}
private void构建脚本(数据表tbl)
{
foreach(待处理行中的数据行r)
{
纬度=r[“纬度”]。ToString();
经度=r[“经度”]。ToString();
Locations+=Environment.NewLine+“map.addOverlay(新的GMarker(新的GLatLng(“+纬度+”,“+经度+”));”;
i++;
}
js.Text=@”
函数初始化(){
if(GBrowserIsCompatible()){
var map=newgmap2(document.getElementById('map_canvas');
地图设置中心(新玻璃(“+纬度+”,“+经度+”),10);
“+位置+@”
openInfoWindow(map.getCenter(),document.createTextNode(“+Latitude+@”);
map.setUIToDefault();
}
}
";
}
我怎么做
谢谢
var方向显示;
var directionsService=new google.maps.directionsService();
函数初始化映射(){
directionsDisplay=new google.maps.DirectionsRenderer();
var latlng=新的google.maps.latlng(-34.397150.644);
变异性肌肽=
{
缩放:8,
中心:拉特林,
mapTypeId:google.maps.mapTypeId.ROADMAP
};
var map=new google.maps.map(document.getElementById(“map”),myOptions);
方向显示.setMap(地图);
DirectionDisplay.setPanel(document.getElementById('directionpanel');
var control=document.getElementById('control');
control.style.display='block';
}
函数calcRoute(){
var start=document.getElementById('startvalue').value;
var end=document.getElementById('endvalue').value;
var请求={
来源:start,
目的地:完,
travelMode:google.maps.Directions travelMode.DRIVING
};
路由(请求、功能(响应、状态){
if(status==google.maps.directionstatus.OK){
方向显示。设置方向(响应);
}
});
}
功能按钮1_onclick(){
calcRoute();
}
window.onload=初始化映射;
发件人:
致:
您提供的代码使用的是正式弃用的,将继续使用到2013年5月19日。不鼓励使用该版本的API进行新的开发。在中的点之间使用,要跟随道路,请参见
<html>
<head>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
var directionsDisplay;
var directionsService = new google.maps.DirectionsService();
function InitializeMap() {
directionsDisplay = new google.maps.DirectionsRenderer();
var latlng = new google.maps.LatLng(-34.397, 150.644);
var myOptions =
{
zoom:8,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map"), myOptions);
directionsDisplay.setMap(map);
directionsDisplay.setPanel(document.getElementById('directionpanel'));
var control = document.getElementById('control');
control.style.display = 'block';
}
function calcRoute() {
var start = document.getElementById('startvalue').value;
var end = document.getElementById('endvalue').value;
var request = {
origin: start,
destination: end,
travelMode: google.maps.DirectionsTravelMode.DRIVING
};
directionsService.route(request, function (response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
}
});
}
function Button1_onclick() {
calcRoute();
}
window.onload = InitializeMap;
<table id ="control">
<tr>
<td>
<table>
<tr>
<td>From:</td>
<td>
<input id="startvalue" type="text" style="width: 305px" /></td>
</tr>
<tr>
<td>To:</td>
<td><input id="endvalue" type="text" style="width: 301px" /></td>
</tr>
<tr>
<td align ="right">
<input id="Button1" type="button" value="GetDirections" onclick="return Button1_onclick()" /></td>
</tr>
</table>
</td>
</tr>
<tr>
<td valign ="top">
<div id ="directionpanel" style="height: 390px;overflow: auto" ></div>
</td>
<td valign ="top">
<div id ="map" style="height: 390px; width: 489px"></div>
</td>
</tr>
</table>