Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 向Google Map javascript添加服务器端纬度/经度值_C#_Javascript_Asp.net_Google Maps Api 2 - Fatal编程技术网

C# 向Google Map javascript添加服务器端纬度/经度值

C# 向Google Map javascript添加服务器端纬度/经度值,c#,javascript,asp.net,google-maps-api-2,C#,Javascript,Asp.net,Google Maps Api 2,我正在尝试将谷歌地图添加到我的一个页面中 在我的代码隐藏中,我有一个地图的中心点,以及一组我想要绘制的纬度/经度: protected void Page_Load(object sender, EventArgs e) { Point center = new Point { latitude = 28.42693F, longitude = -81.4673F }; List<Point> points = new List<Point>();

我正在尝试将谷歌地图添加到我的一个页面中

在我的代码隐藏中,我有一个地图的中心点,以及一组我想要绘制的纬度/经度:

protected void Page_Load(object sender, EventArgs e)
{
    Point center = new Point { latitude = 28.42693F, longitude = -81.4673F };

    List<Point> points = new List<Point>();
    points.Add(new Point { latitude = 28.43039F, longitude = -81.47186F });
    points.Add(new Point { latitude = 28.36906F, longitude = -81.56063F });

    Point[] pointArray = points.ToArray();
}


public class Point
{
    public float latitude;
    public float longitude;
}
受保护的无效页面加载(对象发送方,事件参数e)
{
点中心=新点{纬度=28.42693F,经度=-81.4673F};
列表点=新列表();
添加(新点{纬度=28.43039F,经度=-81.47186F});
添加(新点{纬度=28.36906F,经度=-81.56063F});
Point[]pointArray=points.ToArray();
}
公共课点
{
公共浮动纬度;
公共浮标经度;
}
在我的页面上,我有以下javascript:

<script type="text/javascript">

    function initialize() {
        if (GBrowserIsCompatible()) {
            var map = new GMap2(document.getElementById("map_canvas"));
            map.setCenter(new GLatLng(28.42693, -81.4673), 13);
            //map.setUIToDefault();

            var blueIcon = new GIcon(G_DEFAULT_ICON);
            blueIcon.image = "http://www.google.com/intl/en_us/mapfiles/ms/micons/blue-dot.png";
            markerOptions = { icon: blueIcon };


            var point = new GLatLng(28.43039, -81.47186);
            map.addOverlay(new GMarker(point, markerOptions));

            point = new GLatLng(28.36906, -81.56063);
            map.addOverlay(new GMarker(point, markerOptions));
        }
    }

</script>

函数初始化(){
if(GBrowserIsCompatible()){
var map=newgmap2(document.getElementById(“map_canvas”);
赛特中心地图(新格拉特林(28.42693,-81.4673),13);
//map.setUIToDefault();
var blueIcon=新GIcon(G_默认图标);
blueIcon.image=”http://www.google.com/intl/en_us/mapfiles/ms/micons/blue-dot.png";
markerOptions={icon:blueIcon};
var点=新玻璃(28.43039,-81.47186);
map.addOverlay(新的GMarker(点,标记选项));
点=新玻璃(28.36906,-81.56063);
map.addOverlay(新的GMarker(点,标记选项));
}
}

这些值现在已经硬编码到javascript中进行测试,但我需要从代码中获取动态值。如何做到这一点?

一种快速而肮脏的方法是在代码中创建一个字符串,创建一个lat/long值的JavaScript数组。然后可以在.ASPX中添加一个,并将其设置为字符串值。或者创建点的JSON表示。它适用于小型一次性场景。因此,您的JavaScript最终可能会如下所示:

<script type="text/javascript">

    function initialize() {
        if (GBrowserIsCompatible()) {
            var map = new GMap2(document.getElementById("map_canvas"));
            <asp:Literal id="litMapCenter" runat="server"/>
            //map.setUIToDefault();

            var blueIcon = new GIcon(G_DEFAULT_ICON);
            blueIcon.image = "http://www.google.com/intl/en_us/mapfiles/ms/micons/blue-dot.png";
            markerOptions = { icon: blueIcon };

            <asp:Literal id="litMapPoints" runat="server"/>
        }
    }

</script>

函数初始化(){
if(GBrowserIsCompatible()){
var map=newgmap2(document.getElementById(“map_canvas”);
//map.setUIToDefault();
var blueIcon=新GIcon(G_默认图标);
blueIcon.image=”http://www.google.com/intl/en_us/mapfiles/ms/micons/blue-dot.png";
markerOptions={icon:blueIcon};
}
}

然后在代码隐藏中使用适当的JavaScript设置litMapPoints和litMapCenter。

一种快速而肮脏的方法是在代码隐藏中创建一个字符串,创建一个lat/long值的JavaScript数组。然后可以在.ASPX中添加一个,并将其设置为字符串值。或者创建点的JSON表示。它适用于小型一次性场景。因此,您的JavaScript最终可能会如下所示:

<script type="text/javascript">

    function initialize() {
        if (GBrowserIsCompatible()) {
            var map = new GMap2(document.getElementById("map_canvas"));
            <asp:Literal id="litMapCenter" runat="server"/>
            //map.setUIToDefault();

            var blueIcon = new GIcon(G_DEFAULT_ICON);
            blueIcon.image = "http://www.google.com/intl/en_us/mapfiles/ms/micons/blue-dot.png";
            markerOptions = { icon: blueIcon };

            <asp:Literal id="litMapPoints" runat="server"/>
        }
    }

</script>

函数初始化(){
if(GBrowserIsCompatible()){
var map=newgmap2(document.getElementById(“map_canvas”);
//map.setUIToDefault();
var blueIcon=新GIcon(G_默认图标);
blueIcon.image=”http://www.google.com/intl/en_us/mapfiles/ms/micons/blue-dot.png";
markerOptions={icon:blueIcon};
}
}

然后在代码隐藏中使用适当的JavaScript设置litMapPoints和litMapCenter。

您可以在代码隐藏中使用类似的内容

ClientScript.RegisterStartupScript(this.getType(), "whateveryourkeyis", string.Format("longitude={0};", pointArray[0].longitude), true);
这样,您只需创建一个名为“经度”的jscript变量,并使用.NET代码值对其进行初始化


(这是动态编写的,如果其中有bug,请原谅:-)

您可以在代码中使用类似的内容

ClientScript.RegisterStartupScript(this.getType(), "whateveryourkeyis", string.Format("longitude={0};", pointArray[0].longitude), true);
这样,您只需创建一个名为“经度”的jscript变量,并使用.NET代码值对其进行初始化

(这是在飞行中写的,所以如果有bug,请原谅我:-)