将地理坐标转换为地址C#或jQuery [英] Translate geo coordinates to address C# or jQuery

查看:225
本文介绍了将地理坐标转换为地址C#或jQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

In my jQuery code I can get user Geo coordinates. Now how can I translate GEO coordinates to an address either using C# or jQuery.

推荐答案

在文本框中输入Lat,Lng,然后点击开始。

Try this using jQuery. Give Lat, Lng in text box and click GO.

UPDATED

<!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>

这篇关于将地理坐标转换为地址C#或jQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆