通过HTTP回调函数谷歌地理code?回调、函数、地理、HTTP

2023-09-10 13:44:37 作者:仰望你的星空

我想通过HTTP使用谷歌的地理code 功能转换城市名称为经度和纬度在我的AJAX的Web应用程序。

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.

不过,似乎存在的HTTP地理codeR功能没有任何回调函数

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

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

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

Is that true, no callback function exists?

因为如果这是真的,这实际上意味着通过HTTP API的谷歌地理code是没用的AJAX使用,因为JavaScript的将抛出一个跨域异常错误的时候。的

我如何能在JavaScript中使用通过HTTP API地理code在我的AJAX的web应用程序的任何想法?

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

注意:我做的不可以要使用的完全成熟的谷歌地图API,它是大约200KB下载(即GClientGeo codeR)。我想使用的HTTP API B C的/它的超快速的响应能力和缺乏不必下载庞大的完全成熟的互动谷歌地图API需要我的网络用户。

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.

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

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

感谢

推荐答案

嗯....我想你必须有你的AJAX调用回你自己的服务器,然后调用谷歌的地理code从服务器。

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.

这就是我怎么AJAX地理编码,这一切都在我的ASP.NET code。

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

编辑:

在ASP.NET web表单的环境,我可能实现这是一个轻量级的ASHX文件,但为了简单起见,这里是一个ASPX例如:

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

在上面的例子中,在.NET页面仅将请求传递沿

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

但在真实的环境下,我宁愿我的.NET code做的不仅仅是在传递数据。这样,在发送之前,我可以做的错误处理,过滤,验证,业务逻辑,所有的服务器上,这些数据转移到客户端。

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.