JavaScript代码重写部分用C# [英] Rewrite part of javascript with C#
问题描述
我写在C#这个程序应该显示谷歌地图。我使用谷歌地图API的JavaScript这是我能找到的最好的之一。随着程序,你应该能够搜索的地方。
在code:
的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 =http://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
我在某种程度上能够编辑的经纬度使用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屋!