JavaScript代码重写部分用C# [英] Rewrite part of javascript with C#

查看:121
本文介绍了JavaScript代码重写部分用C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写在C#这个程序应该显示谷歌地图。我使用谷歌地图API的JavaScript这是我能找到的最好的之一。随着程序,你应该能够搜索的地方。

在code:

\r
\r

的window.onload =函数(){\r
\r
    VAR经纬度=新google.maps.LatLng(52.785804,6.897585);\r
    VAR的选择= {\r
        变焦:15,\r
        中心:经纬度,\r
        mapTypeId设为:google.maps.MapTypeId.ROADMAP\r
    };\r
    VAR地图=新google.maps.Map(的document.getElementById(地图),选件);\r
}

\r

HTML,身体{\r
    保证金:0;\r
    宽度:100%;\r
    高度:100%;\r
    溢出:隐藏;\r
}\r
\r
#map {\r
    宽度:80%;\r
    高度:100%;\r
}

\r

<!DOCTYPE HTML PUBLIC - // W3C // DTD HTML 4.0过渡// ENGT&;\r
< HTML和GT;\r
\r
< HEAD>\r
    <标题>谷歌地图< /标题>\r
    <脚本SRC =htt​​p://maps.google.com/maps/api/js?sensor=false类型=文/ JavaScript的>< / SCRIPT>\r
\r
< /头>\r
\r
<身体GT;\r
    &所述;格ID =地图>\r
    < / DIV>\r
< /身体GT;\r
\r
< / HTML>

\r

\r
\r

我在某种程度上能够编辑的经纬度使用C#?还是没有人知道使用谷歌地图API与C#的另一种方式?


解决方案

如果您不使用MVC或其他服务器端的技术,这个特定的页面上你唯一的选择是将加载拉/长从AJAX调用。

  $。阿贾克斯({
    网址:URL /到/你/ API /是/收益/经/纬度
    成功:函数(结果){
        //处理您的JSON结果并设置纬度/长
    }
});

该API可以使用任何语言(包括C#)

在服务器端被写入

I'm writing this program in C# which should display Google Maps. I'm using the Google Maps JavaScript API which is the best one I could find. With the program you should be able to search for places.

The code:

window.onload = function() {

    var latlng = new google.maps.LatLng(52.785804, 6.897585);
    var options = {
        zoom: 15,
        center: latlng,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    var map = new google.maps.Map(document.getElementById("map"), options);
}

html, body {
    margin: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

#map {
    width: 80%;
    height: 100%;
}

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>

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

</head>

<body>
    <div id="map">
    </div>
</body>

</html>

Am I in some way able to edit the latlng using C#? Or does someone know an alternative way to use the Google Maps API with C#?

解决方案

If you are not using MVC or other server side technologies on this specific page your only option would be to load the lat/long from an AJAX call.

$.ajax({
    url: "url/to/your/api/that/returns/lat/long",
    success: function(result) {
        // process your JSON result and set the lat/long
    }
});

the API can be written on the server side using any language (including c#)

这篇关于JavaScript代码重写部分用C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆