gpt4 book ai didi

javascript - 如何在 mvc 的 gmap 脚本中添加我自己的位置

转载 作者:行者123 更新时间:2023-11-29 20:11:37 24 4
gpt4 key购买 nike

代码运行良好,但我想添加我自己的位置。例如在下面的脚本中

map.setCenter(new google.maps.LatLng(37.4419, -122.1419), 13);

如果我想要印度浦那 map ,会给我那个特定位置的 map 那么我需要把这个位置放在哪里,或者我怎样才能得到这个位置的经纬度?

我该怎么做请帮助我,我是 mvc 的新手。

<script type="text/javascript" src="http://www.google.com/jsapi?key=mykey"></script>

<script type="text/javascript">
var allMarks = [];
google.load("maps", "2");

//This function will help us to add the mark at
//location where user has double clicked. Then
//we will add all the marks in our array so that
//we can send it back to the controller
function initialize() {
var map = new google.maps.Map2(document.getElementById("map"));
map.setCenter(new google.maps.LatLng(37.4419, -122.1419), 13);
marker = new google.maps.marker
map.setUIToDefault();
GEvent.addListener(map, "dblclick", function(overlay, latlng) {
if (latlng) {
var mark = new GMarker(latlng);
allMarks.push(latlng);
map.addOverlay(mark);
}
});

}
google.setOnLoadCallback(initialize);


//This function will be called for saving the mark
//for that it will send the data back to the controller
function saveMap() {

//gmap object with all values of the map mark
var gmap = {
Locations: allMarks,
Description: Description.value
}

//Ajax call for saving the data at the server. It will send the gmap
//object tot the server
$.ajax({
type: "POST",
url: "/Home/Create",
data: gmap
});
}
</script>

最佳答案

假设你只需要这样做一次,而不是动态地对任意位置进行地理编码,那么你所要做的就是替换坐标

map.setCenter(new google.maps.LatLng(37.4419, -122.1419), 13);

使用您自己的坐标和缩放级别。您可以通过多种方式轻松地手动找到某个位置的纬度/经度 - 我喜欢 getlatlon.com .

这真的是你的问题吗?如果您需要使用任意地址,例如根据用户输入,并将 map 居中,您可能想查看 Google 的 geocoding API .

关于javascript - 如何在 mvc 的 gmap 脚本中添加我自己的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9339001/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com