Google地理编码通过HTTP回调函数? [英] Google Geocode via HTTP callback function?

查看:118
本文介绍了Google地理编码通过HTTP回调函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Google地理服务透过HTTP 功能将城市名称翻译成我的AJAX网路应用程式的经度和纬度。



但是,对于HTTP地址解析器功能,似乎没有回调函数



http://code.google.com/apis/maps/documentation/geocoding/index.html



这是真的,没有回调函数存在吗?



因为如果这是真的,这本质上意味着通过HTTP api的Google地理编码在与AJAX一起使用时是无用的,因为JavaScript会抛出一个跨域异常错误。 / em>

有关如何通过JavaScript在AJAX Web应用程序中通过HTTP api使用地理编码的任何想法?



注意:我希望使用完整的Google Maps API(大约200kb下载)(即GClientGeocoder)。我想使用它的HTTP api b / c超快的响应速度和缺乏需要我的网络用户从下载巨大的充分互动的google地图api。



例如
http://maps.google.com / maps / geo?output = json& sensor = false& key = {API_KEY}& q = {CITY,STATE}& CALLBACK = ????



感谢

解决方案

hmm ....我想你必须将AJAX调用回你自己服务器,然后从您的服务器调用Google的地理编码。



这是我做AJAX地理编码,这一切都通过我的ASP.NET代码。



编辑:



在ASP.NET webforms环境中,我可能将它实现为一个轻量级的ASHX文件,但为了简单起见,一个ASPX示例:

  public partial class GoogleHandler:System.Web.UI.Page 
{
protected void Page_Load(object sender,EventArgs e){
Response.Write(GetGoogleXML(http:// pseudo_googlegeocode?parameter =+ parametersFromQuerystring);
}
}



在上面的例子中,.NET页面只传递请求。



但在实际环境中,我宁愿我的.NET代码不仅仅是传递数据。这样,我可以在将数据发送到客户端之前对服务器进行错误处理,过滤,验证,业务逻辑。



抽象。即我可能从google更改为yahoo地理编码。以这种方式,我只需要改变我的服务逻辑,并让客户端只收到一组通用的坐标/位置数据。



此外,使用该抽象我实际上可以聚合来自各种地理编码数据源的多个数据。同样,服务器负责聚合,客户端只接收并显示过滤的数据。


I want to use the google geocode via HTTP functionality to translate a city name into longitude and latitude in for my AJAX web application.

However, it appears that no callback function exists for the HTTP geocoder functionality

http://code.google.com/apis/maps/documentation/geocoding/index.html

Is that true, no callback function exists?

Because if that is true, it essentially means that the Google geocode via HTTP api is useless when used with AJAX because JavaScript will throw a crossdomain exception error.

Any ideas on how I can use the geocode via HTTP api in my AJAX web application in JavaScript?

Note: I do not want to use the full blown Google Maps API which is approx 200kb download (i.e. GClientGeocoder). I want to use the HTTP api b/c of it's super quick responsiveness and lack of needing my web users from having to download the huge full blown interactive google maps api.

E.g. http://maps.google.com/maps/geo?output=json&sensor=false&key={API_KEY}&q={CITY,STATE}&CALLBACK=????

Thanks

解决方案

hmm....I think you'd have to have your AJAX call back to your own server, and then call Google's Geocode from your server.

Thats how I do AJAX geocoding, it all goes through my ASP.NET code.

EDIT:

In the ASP.NET webforms environment I might implements this as a lightweight ASHX file, but for the purposes of simplicity, here's an ASPX example:

public partial class GoogleHandler : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e) {
        Response.Write(GetGoogleXML("http://pseudo_googlegeocode?parameter=" + parametersFromQuerystring);
    }
}

In the example above, the .NET page is only passing the request along.

But in a real environment, I'd rather my .NET code do more than just pass the data over. This way I can do error handling, filtering, validation, business logic, all on the server, before sending that data over to the client.

Also, this allows for greater abstraction. i.e, I might change from google to yahoo geocoding. In this way I'd only have to change my serve logic, and leave the client to just receive a generic set of coordinates/location data.

Also, using that abstraction I could actually aggregate multiple data from various geocoding data sources. Again, the server takes care of aggregating, the client just receives and displays the filtered data.

这篇关于Google地理编码通过HTTP回调函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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