首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将地理坐标转换为地址C#或jQuery

将地理坐标转换为地址C#或jQuery
EN

Stack Overflow用户
提问于 2013-05-27 17:12:32
回答 2查看 1.3K关注 0票数 1

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

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-05-27 17:19:12

使用jQuery尝试一下。在文本框中输入Lat,Lng,然后单击GO。

已更新

代码语言:javascript
复制
<!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>
票数 1
EN

Stack Overflow用户

发布于 2013-05-27 18:02:30

简短的回答是:不。

您正在尝试实现的目标称为Reverse Geocoding

说明:Google's usage limitations特别提到,他们禁止用户在不在地图上显示结果的情况下使用地理编码接口。

虽然没有说明地图应该位于页面上的哪个位置,以及它应该满足哪些要求,但意图是相当明显的。

有几个可供选择的地理编码引擎。试试这些:

Geonames

Bing maps

Yahoo maps

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16769865

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档