Geoencode地址到GPS坐标 [英] Geoencode Address to GPS Coordinates

查看:138
本文介绍了Geoencode地址到GPS坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找geoencode地址并将其转换为GPS坐标。基本上,

I'm looking to geoencode an address and convert it to GPS Coordinates. Basically,

var address;

//  Google/Yahoo/whatever program to convert address to GPS coordinates

var output=xx.xxxxxxx,xx.xxxxxxx

我研究过Google和Yahoo API,但似乎无法让他们的代码在我的Google小工具中工作。有什么建议?

I've researched Google and Yahoo APIs, but can't seem to get their codes to work in my Google Gadget. Any suggestions?

预先感谢!

推荐答案

以下是我为地址到GPS需求所做的工作:

Here's what I did for my address-to-gps-coords needs:

function get_coords(address)
{
    var gc      = new google.maps.Geocoder(),
        opts    = { 'address' : address };

    gc.geocode(opts, function (results, status)
    {
        if (status == google.maps.GeocoderStatus.OK)
        {   
            var loc     = results[0].geometry.location,
                lat     = loc.$a,
                long    = loc.ab;

            // Success.  Do stuff here.
        }
        else
        {
            // Ruh roh.  Output error stuff here
        }
    });
}

然后你就像 get_coords('1600 Pennsylvania Avenue NW NW 20500'),它会返回经纬度。

Then you call it like get_coords('1600 Pennsylvania Avenue NW Washington, DC 20500') and it'll return the latitude and longitude.

您需要提供自己的Google地图当然,API键可以使它工作。

You'll need to supply your own Google Maps API key to make it work, of course.

希望这有助于您!

这篇关于Geoencode地址到GPS坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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