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

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

问题描述

我正在用 C# 编写这个程序,它应该显示谷歌地图.我正在使用 Google Maps JavaScript API,这是我能找到的最好的 API.使用该程序,您应该能够搜索地点.

代码:

window.onload = function() {var latlng = new google.maps.LatLng(52.785804, 6.897585);变量选项 = {变焦:15,中心:latlng,mapTypeId: google.maps.MapTypeId.ROADMAP};var map = new google.maps.Map(document.getElementById("map"), options);}

html, body {边距:0;宽度:100%;高度:100%;溢出:隐藏;}#地图 {宽度:80%;高度:100%;}

<头><title>谷歌地图</title><script src="http://maps.google.com/maps/api/js?sensor=false" type="text/javascript"></script><身体><div id="地图">

</html>

我能以某种方式使用 C# 编辑 latlng 吗?或者有人知道通过 C# 使用 Google Maps API 的替代方法吗?

解决方案

如果您没有在此特定页面上使用 MVC 或其他服务器端技术,您唯一的选择是加载 lat/long来自 AJAX 调用.

$.ajax({url: "url/to/your/api/that/returns/lat/long",成功:功能(结果){//处理您的 JSON 结果并设置经纬度}});

可以使用任何语言(包括 c#)在服务器端编写 API

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#)

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

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