Google Maps v3 地理编码服务器端 [英] Google Maps v3 geocoding server-side

查看:24
本文介绍了Google Maps v3 地理编码服务器端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 ASP.NET MVC 3 和 Google Maps v3.我想在一个动作中进行地理编码.这就是将有效地址传递给 Google 并获取纬度和经度.我见过的所有关于地理编码的在线示例都涉及客户端地理编码.您将如何在使用 C# 的操作中执行此操作?

I'm using ASP.NET MVC 3 and Google Maps v3. I'd like to do geocoding in an action. That is passing a valid address to Google and getting the latitude and longitude back. All online samples on geocoding that I've seen have dealt with client-side geocoding. How would you do this in an action using C#?

推荐答案

我不确定我是否理解正确,但这是我做的方式(如果你有兴趣)

I am not sure if I understand you correctly but this is the way I do it (if you are interested)

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);
    }
}

使用扩展方法这里 &Json.Net

using the extension methods here & Json.Net

这篇关于Google Maps v3 地理编码服务器端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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