如何使用服务器端编程获取位置? [英] How to get location using server side programming?

查看:69
本文介绍了如何使用服务器端编程获取位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好



使用以下代码在javascript中获取纬度和经度位置

  function  getCountry(latLng){
geocoder.geocode({' latLng':latLng},
function (结果,状态){
if (status == google.maps.GeocoderStatus.OK){
if (结果[ 0 ]){
for var i = 0 ; i< results [ 0 ]。address_components.length; i ++){
if (结果[ 0 ]。address_components [i] .types [ 0 ] == country){
alert(results [ 0 ]。address_components [i] .long_name);
}
}
}
其他 {
alert( 无结果);
}
}
其他 {
alert( 状态: + status);
}
}
);
}





以下代码提供位置名称的纬度和经度。



 无效 GoogleGeoCode( string 地址)
{
string url = http ://maps.googleapis.com/maps/api/geocode/json传感器=真安培;地址=;

动态 googleResults = new Uri(网址+地址).GetDynamicJsonObject() ;
foreach var 结果 in googleResults.results)
{
Console.WriteLine( [ + result.geometry.location.lat + + result.geometry.location.lng + ] + result.formatted_address);
}
}





但是,如何使用c#从服务器端获取位置而不是在客户端使用

纬度和经度?



谢谢。

解决方案

您好Hasbina,



https://github.com/chadly/Geocoding.net [ ^ ]



API返回纬度/经度坐标和规范化地址信息。这可用于执行地址验证,用户输入地址的实时映射,距离计算等等。



简单示例:



 IGeoCoder geoCoder =  new  GoogleGeoCoder(  my-api-key); 
地址[]地址= geoCoder.GeoCode( 123 Main St);



它还可用于从纬度/经度坐标(又名反向地理编码)返回地址信息:



< pre lang =c#> IGeoCoder geoCoder = new YahooGeoCoder( 我的应用内-ID);
地址[]地址= geoCoder.ReverseGeoCode( 38 8976777 , - 77。 036517 );





干杯,

Edo


Hi

Get location from latitude and longitude using the below code in javascript

function getCountry(latLng) {
    geocoder.geocode( {'latLng': latLng},
      function(results, status) {
        if(status == google.maps.GeocoderStatus.OK) {
          if(results[0]) {
            for(var i = 0; i < results[0].address_components.length; i++) {
              if(results[0].address_components[i].types[0] == "country") {
                alert(results[0].address_components[i].long_name);
              }
            }
          }
          else {
            alert("No results");
          }
        }
        else {
          alert("Status: " + status);
        }
      }
    );
  }



The below code provide the latitude and longitude from location name.

void GoogleGeoCode(string address)
{
    string url = "http://maps.googleapis.com/maps/api/geocode/json?sensor=true&address=";

    dynamic googleResults = new Uri(url + address).GetDynamicJsonObject();
    foreach (var result in googleResults.results)
    {
        Console.WriteLine("[" + result.geometry.location.lat + "," + result.geometry.location.lng + "] " + result.formatted_address);
    }
}



But, how to get location from server side with c# instead it in client side using
latitude and longitude?

Thanks.

解决方案

Hi Hasbina,

https://github.com/chadly/Geocoding.net[^]

The API returns latitude/longitude coordinates and normalized address information. This can be used to perform address validation, real time mapping of user-entered addresses, distance calculations, and much more.

Simple Example:

IGeoCoder geoCoder = new GoogleGeoCoder("my-api-key");
Address[] addresses = geoCoder.GeoCode("123 Main St");


It can also be used to return address information from latitude/longitude coordinates (aka reverse geocoding):

IGeoCoder geoCoder = new YahooGeoCoder("my-app-ID");
Address[] addresses = geoCoder.ReverseGeoCode(38.8976777, -77.036517);



Cheers,
Edo


这篇关于如何使用服务器端编程获取位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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