Javascript Google地图-VB.Net中的JSON标记

Javascript Google地图-VB.Net中的JSON标记,javascript,vb.net,json,google-maps,Javascript,Vb.net,Json,Google Maps,当前正在构建映射应用程序,从数据库读取点 在这个级别上对Javascript是新的,所以现在有点迷失了 从SQL数据源在VB.Net中创建Json 有人能帮我编辑代码吗?这样,在不创建新地图的情况下,标记就添加到现有地图上了?我所做的任何编辑都不会添加点 VB.Net Dim markers As New List(Of String) Dim nearbyLocations = CType(sqlData.Select(DataSourceSelectArguments.Empty), Dat

当前正在构建映射应用程序,从数据库读取点

在这个级别上对Javascript是新的,所以现在有点迷失了

从SQL数据源在VB.Net中创建Json

有人能帮我编辑代码吗?这样,在不创建新地图的情况下,标记就添加到现有地图上了?我所做的任何编辑都不会添加点

VB.Net

Dim markers As New List(Of String)
Dim nearbyLocations = CType(sqlData.Select(DataSourceSelectArguments.Empty), DataView)
For Each location As DataRowView In nearbyLocations
    markers.Add(String.Format("{{ title: ""Name {0}"", position: new google.maps.LatLng({1}, {2}) }}", location("AccName"), location("Latitude"), location("Longitude")))
Next

Dim locations = "[" & String.Join(",", markers.ToArray()) & "]"
ClientScript.RegisterStartupScript(Me.GetType(), "LoadMap",_
     String.Format("init_map('map', {0}, {1}, 13, {2});", lat, lng, locations), True)
剧本

function init_map(map_canvas_id, lat, lng, zoom, markers) {
var myLatLng = new google.maps.LatLng(lat, lng);

var options = {
    zoom: zoom,
    center: myLatLng,
    mapTypeId: google.maps.MapTypeId.ROADMAP
};


map = new google.maps.Map(document.getElementById(map_canvas_id), options);


if (markers && markers.length > 0) {
    var bounds = new google.maps.LatLngBounds();

    for (var i = 0; i < markers.length; i++) {
        var marker = new google.maps.Marker(markers[i]);
        marker.setMap(map);

        bounds.extend(marker.getPosition());
    }

    map.fitBounds(bounds);
    map.setCenter(bounds.getCenter());
}
}
函数初始化映射(映射画布id、lat、lng、缩放、标记){
var mylatng=new google.maps.LatLng(lat,lng);
变量选项={
缩放:缩放,
中心:myLatLng,
mapTypeId:google.maps.mapTypeId.ROADMAP
};
map=new google.maps.map(document.getElementById(map\u canvas\u id),选项);
如果(markers&&markers.length>0){
var bounds=new google.maps.LatLngBounds();
对于(var i=0;i
在代码隐藏中:

Dim markers As New List(Of String)
Dim nearbyLocations = CType(sqlData.Select(DataSourceSelectArguments.Empty), DataView)
For Each location As DataRowView In nearbyLocations
    markers.Add(" { ""title"" : """ & location("AccName") & """, ""lat"" : " & location("Latitude") & ", ""long"" : " & location("Longitude") & " } ")
Next

Dim locations = "[" & String.Join(",", markers.ToArray()) & "]"
ClientScript.RegisterStartupScript(Me.GetType(), "LoadMap",_
    String.Format("init_map('map', {0}, {1}, 13, {2});", lat, lng, locations), True)
在aspx页面中:

//<HTML> stuff....
//...
//...

var map;

function init_map(map_canvas_id, lat, lng, zoom, markers) {
var myLatLng = new google.maps.LatLng(lat, lng);

var options = {
    zoom: zoom,
    center: myLatLng,
    mapTypeId: google.maps.MapTypeId.ROADMAP
};

map = new google.maps.Map(document.getElementById(map_canvas_id), options);

var positions = [<% Response.Write(String.Join(",", markers.ToArray())) %>];    
var marker;
var curPosition;
for (var i = 0; i < positions.length; i++) {
    curPosition = positions[i];
    marker = new google.maps.Marker({
        map: map,
        position: new google.maps.LatLng(curPosition.lat,curPosition.long),
        title: curPosition.title
    });
}

//..</HTML> stuff
//东西。。。。
//...
//...
var映射;
函数初始化映射(映射画布id、lat、lng、缩放、标记){
var mylatng=new google.maps.LatLng(lat,lng);
变量选项={
缩放:缩放,
中心:myLatLng,
mapTypeId:google.maps.mapTypeId.ROADMAP
};
map=new google.maps.map(document.getElementById(map\u canvas\u id),选项);
var头寸=[];
var标记;
可变电流位置;
对于(变量i=0;i
谢谢。如何在VB中引用此选项以执行脚本?我想您已经绘制了一张地图,并且希望添加新标记。如何获得“新”标记标记列表?我要做的是对返回json的Web服务进行Jquery Ajax调用。根据输入字段,通过VB点击按钮从SQL数据源检索新标记。之前没有使用过Jquery,所以选择了VB/Javascript路线。想法是用户可以更改参数,并根据这些参数添加标记。那么您如何能够创建了多个映射?在上面的代码中不是只创建了一次映射吗?在这段代码中是的,但是我也有一个函数执行onload来创建映射。我试图编辑脚本/vb来添加到这个创建的映射中,但没有用。