【问题标题】:Translate geo coordinates to address C# or jQuery将地理坐标转换为地址 C# 或 jQuery
【发布时间】:2013-05-27 09:12:32
【问题描述】:

在我的 jQuery 代码中,我可以获得用户地理坐标。 现在如何使用 C# 或 jQuery 将 GEO 坐标转换为地址。

【问题讨论】:

    标签: jquery google-maps c#-4.0 geolocation bing-maps


    【解决方案1】:

    使用 jQuery 试试这个。在文本框中输入 Lat、Lng,然后单击 GO。

    更新

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>Testing</title>
        <script src="scripts/jquery-1.9.1.min.js" type="text/javascript"></script>
        <script src="http://maps.googleapis.com/maps/api/js?key=AIzaSyA7IZt-36CgqSGDFK8pChUdQXFyKIhpMBY&sensor=true" type="text/javascript"></script>
        <script type="text/javascript">
    
            var map;
            var geocoder;
            var marker;
            var latlng;
            var infowindow;
    
            $(document).ready(function() {
    
            });
    
            function initialize() {
                var mapOptions = {
                    //center: new google.maps.LatLng(40.4230, 98.7372),   // Coimbatore = (11.0168445, 76.9558321)
                    zoom: 3,
                    mapTypeId: google.maps.MapTypeId.ROADMAP
                };
                map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);
    
                geocoder = new google.maps.Geocoder();
                infowindow = new google.maps.InfoWindow();
    
                var latlngStr = $('#address').val().split(",");
                var lat = parseFloat(latlngStr[0]);
                var lng = parseFloat(latlngStr[1]);
    
                $('#latitude').val(lat);
                $('#longitude').val(lng);
    
                latlng = new google.maps.LatLng(lat, lng);
                marker = new google.maps.Marker({
                    position: latlng,
                    map: map,
                    draggable: true
                });
                map.setCenter(latlng);
    
                geocoder.geocode({ 'latLng': latlng }, function(results, status) {
                    infowindow.setContent(results[0].formatted_address);
                    $('#txtAddress').val(results[0].formatted_address);
                });
            }
    
        </script>
    </head>
    <body>
        <label>
            Lat, Lng:
        </label>
        <input id="address" type="text" placeholder="10.9435131, 76.9383790" />
        <input type="button" value="Go" onclick="initialize()" />
        <br />
        <br />
        <div id="map-canvas" style="width: 10px; height: 10px; display: none;">
        </div>
        <label>
            Latitude:
        </label>
        <input id="latitude" type="text" />
        <br />
        <label>
            Longitude:
        </label>
        <input id="longitude" type="text" />
        <label>
            Address:
        </label>
        <textarea rows="3" cols="30" id="txtAddress">
        </textarea>
    </body>
    </html>
    

    【讨论】:

    • 感谢您的回复。我正在寻找地址而不是在地图上显示它。如果您在我们插入 GEO 坐标时查看此网站findlatitudeandlongitude.com/…,右侧会显示它的地址。
    • 对不起,我忘了添加一件事。 点击标记查看地址。
    • 太棒了!有没有一种方法可以直接将地址获取到文本区域,而不是通过单击标记?
    • @Venka Yeluri 所以你不想用地图来查看位置?
    • 事实上我不需要地图,我只需要使用 GEO 坐标显示地址
    【解决方案2】:

    简短回答:不。

    您想要达到的目标称为Reverse Geocoding

    解释:Google's usage limitations 特别提到他们禁止用户使用 Geocoding API 而不在地图上显示结果。

    虽然没有说明地图应该在页面上的什么位置,以及它应该满足哪些要求,但意图是很明显的。

    有几种替代的地理编码引擎。 试试这些:

    Geonames

    Bing maps

    Yahoo maps

    【讨论】:

      猜你喜欢
      • 2021-03-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多