【问题标题】:How do I add my own location in gmap script in mvc如何在 mvc 的 gmap 脚本中添加自己的位置
【发布时间】:2012-02-18 05:56:21
【问题描述】:

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

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

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

我该怎么做请帮助我,我是 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);如果我想显示印度浦那位置的地图,那么我需要在脚本中添加此位置的位置。?

标签: javascript asp.net-mvc google-maps google-maps-api-3


【解决方案1】:

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

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

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-01-28
    • 2014-05-01
    • 1970-01-01
    • 2011-06-30
    • 2018-07-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多