Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 获取城市和州/省或邮政编码的时区偏移量_Asp.net_Api_Timezone - Fatal编程技术网

Asp.net 获取城市和州/省或邮政编码的时区偏移量

Asp.net 获取城市和州/省或邮政编码的时区偏移量,asp.net,api,timezone,Asp.net,Api,Timezone,我有一个asp.net网站,它将使用EST时间托管在服务器上,并且很可能在运行EST的计算机/设备上创建。用户将更新有关北美各地位置的信息。我需要在进行更新的位置的本地时间进行更新的时间戳,而不是服务器或计算机时间。因此,我需要能够获得基于城市和州/省或邮政编码的位置偏移量。我已经看过了,它需要纬度和经度,我没有 您可以从谷歌地图中删除纬度和经度 例如,地址为“加利福尼亚州洛杉矶123街12345”或地址仅为邮政编码“12346” public void GetCoordinate(string

我有一个asp.net网站,它将使用EST时间托管在服务器上,并且很可能在运行EST的计算机/设备上创建。用户将更新有关北美各地位置的信息。我需要在进行更新的位置的本地时间进行更新的时间戳,而不是服务器或计算机时间。因此,我需要能够获得基于城市和州/省或邮政编码的位置偏移量。我已经看过了,它需要纬度和经度,我没有

您可以从谷歌地图中删除纬度和经度

例如,地址为“加利福尼亚州洛杉矶123街12345”或地址仅为邮政编码“12346”

public void GetCoordinate(string address)
{
    WebClient client = new WebClient();
    Uri uri = new Uri(String.Format("http://maps.google.com/maps/geo?output=csv&q=" + HttpUtility.UrlEncode(address)));

    // Return numbers -
    // 1 = Status Code
    // 2 = Accurancy
    // 3 = Latitude
    // 4 = Longitude
    string[] geocodeInfo = client.DownloadString(uri).Split(',');

    decimal latitude = Convert.ToDecimal(geocodeInfo[2]);                
    decimal longitude = Convert.ToDecimal(geocodeInfo[3]);            
}

我建议将创建/更新的时间保存为UTC。显示时,根据用户的时区偏移量(保存在用户配置文件中)将UTC转换为用户的本地时间。

您应该查看GeoIP——它使用IP地址确定计算机的地理位置。正如我所说,用户将基于东海岸,因此计算机时间为EST。这不是我需要的。