如何从asp.net中的地址查找纬度和经度

发布于 2024-12-10 16:33:28 字数 134 浏览 1 评论 0原文

我正在开发一个应用程序,其中我有特定人的地址,现在我想在谷歌地图上找到该人的位置。我想在保存该人的详细信息时保存该人的纬度和经度。如何从地址中找到纬度和经度?

在地址中,我保存了他的城市、州、国家、街道等。

谢谢, 萨洛尼

I m developing one application in which i m having the address of particular person, now i want to find the location of that person on google map. I want to save the latitude and longitude of that person when i m saving his details. How can i find the latitude and longitude from the address?

In address, i m saving his city, state , country, street, etc.

Thanks,
Saloni

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

骄傲 2024-12-17 16:33:29

我“第三”谷歌地理编码器..
这是一个 JavaScript 示例:

//this is fired on the onChange of a dropdown or textbox
     function SetMap(textbox) {

        var postcode = textbox.value;
        if (postcode != '') {
            var geocoder = new google.maps.Geocoder();
            geocoder.geocode({ 'address': postcode }, GeoCodeResult);

        }

    }

    function GeoCodeResult(results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
            map.setCenter(results[0].geometry.location);
            var latlng = results[0].geometry.location.lat() + ', ' +                      results[0].geometry.location.lng();

//set hidden field to lat long
            document.getElementById('<%= hdnMapCoords.ClientID %>').value = latlng;


        }
    }

I "third" the google geocoder..
here's an example in javascript:

//this is fired on the onChange of a dropdown or textbox
     function SetMap(textbox) {

        var postcode = textbox.value;
        if (postcode != '') {
            var geocoder = new google.maps.Geocoder();
            geocoder.geocode({ 'address': postcode }, GeoCodeResult);

        }

    }

    function GeoCodeResult(results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
            map.setCenter(results[0].geometry.location);
            var latlng = results[0].geometry.location.lat() + ', ' +                      results[0].geometry.location.lng();

//set hidden field to lat long
            document.getElementById('<%= hdnMapCoords.ClientID %>').value = latlng;


        }
    }
笑忘罢 2024-12-17 16:33:28

您要做的事情称为地理编码,请参阅Google Geocoding API 上的页面

更新:

您可能需要此功能。它能够迭代数组并在每次地理编码返回后执行回调:

function locate(address, callback) {
    var geocoder = new google.maps.Geocoder(),
        latlong = [];

    geocoder.geocode({
        address: address[0]
    }, function(results, status) {
        if (status === google.maps.GeocoderStatus.OK) {
            latlong.push([results[0].geometry.location.Ma, results[0].geometry.location.Na]);
            address.shift();
            if (typeof callback === 'function') callback(latlong);

            if (address.length === 0) {
                return;
            } else {
                locate(address, callback);
            }
        }
    });
}


/*
 * Sample use
 */
locate(['1 Infinite Loop, Cupertino, CA', '1600 Amphitheatre Parkway, Mountain View, CA'], function(result) {
    console.log(result);
});

不要忘记在脚本之前包含 Google Maps API JS 文件。

<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>

The thing you want to do is called geocoding, see the page on Google Geocoding API

Update:

Probably you will need this function. It is able to iterate over an array and execute a callback after each geocoding return:

function locate(address, callback) {
    var geocoder = new google.maps.Geocoder(),
        latlong = [];

    geocoder.geocode({
        address: address[0]
    }, function(results, status) {
        if (status === google.maps.GeocoderStatus.OK) {
            latlong.push([results[0].geometry.location.Ma, results[0].geometry.location.Na]);
            address.shift();
            if (typeof callback === 'function') callback(latlong);

            if (address.length === 0) {
                return;
            } else {
                locate(address, callback);
            }
        }
    });
}


/*
 * Sample use
 */
locate(['1 Infinite Loop, Cupertino, CA', '1600 Amphitheatre Parkway, Mountain View, CA'], function(result) {
    console.log(result);
});

Don't forget to include Google Maps API JS file before your script.

<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
活泼老夫 2024-12-17 16:33:28

使用谷歌地理编码 API。以下内容也应该有所帮助。

string url = string.Format("http://maps.googleapis.com/maps/api/geocode/xml?address={0}&sensor=false", address);

这将返回一个带有以下内部节点的 xml

<location><lat>12.3456</lat><lng>98.7654</lng></location>

Use google Geocode API. Also following should help.

string url = string.Format("http://maps.googleapis.com/maps/api/geocode/xml?address={0}&sensor=false", address);

This would return you an xml with following inside node

<location><lat>12.3456</lat><lng>98.7654</lng></location>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文