根据地理位置找到感兴趣的地方

时间:2010-02-28 03:17:57

标签: javascript google-maps mapping gps bing-maps

我想知道是否有可能根据从GPS系统收集的纬度/经度信息或近似街道地址获取位置? 在这种情况下,景点被定义为:餐馆,度假村,公园,购物中心,电影院等。

是否有一些在线服务使用bing maps / google maps /其他东西,以某种解析格式提供此类信息?

谢谢

1 个答案:

答案 0 :(得分:4)

在客户端,您使用Google AJAX Search API搜索特定坐标周围的景点:

<!DOCTYPE html>
<html>
<head> 
    <title>Google AJAX Search API Demo</title> 
    <script src="http://www.google.com/jsapi" type="text/javascript"></script> 
    <script type="text/javascript"> 

    google.load('search', '1');

    var localSearch;

    function localSearchComplete() {

      // Check that we got results
        if (localSearch.results && localSearch.results.length > 0) {

            // Loop through our results, printing them to the page.
            var results = localSearch.results;

            document.getElementById('content').innerHTML = "";

            for (var i = 0; i < results.length; i++) {
                document.getElementById('content').innerHTML += 
                    '<div style="clear: both;">' +
                    '<div style="float: left; width: 160px;">' + results[i].title + '</div>' +
                    '<div style="float: left; width: 80px;">' + results[i].lat + '</div>' +
                    '<div style="float: left; width: 80px;">' + results[i].lng + '</div>' +     
                    '<div style="float: left; width: 140px;">' + results[i].streetAddress + '</div>' + 
                    '<div style="float: left; width: 120px;">' + results[i].city + '</div>' +
                    '</div>';                
            }

        }
    }

    function OnLoad() {
        localSearch = new google.search.LocalSearch();

        // Coordinates for "New York, NY"
        localSearch.setCenterPoint("40.70, -74.00");
        localSearch.setSearchCompleteCallback(this, localSearchComplete, null);
        localSearch.execute("restaurants");
    }

    google.setOnLoadCallback(OnLoad);

    </script> 
</head> 
<body style="font-family: Arial; font-size: 11px;"> 
    <div id="content">Loading...</div> 
</body> 
</html>

结果如下:

Local Search Results http://img693.imageshack.us/img693/240/localsearch.png


要以JSON格式从服务器端获得相同的结果,您可能需要查看以下文章:

基本上,您可以按以下格式向Google发出请求:

  

http://ajax.googleapis.com/ajax/services/search/local?v=2.0&q=restaurants+40.70,-74.00

哪个会返回以下JSON:

{
    "responseData": {
        "results": [
            {
                "GsearchResultClass": "GlocalSearch",
                "viewportmode": "explicit",
                "listingType": "local",
                "lat": "40.703684",
                "lng": "-73.994861",
                "accuracy": "8",
                "title": "The River Cafe",
                "titleNoFormatting": "The River Cafe",
                "ddUrl": "http://www.google.com/maps?source\u003duds\u0026daddr\u003d1+Water+Street%2C+Brooklyn%2C+NY+%28The+River+Cafe%29+%4040.703684%2C-73.994861\u0026saddr\u003d40.70%2C-74.00",
                "ddUrlToHere": "http://www.google.com/maps?source\u003duds\u0026daddr\u003d1+Water+Street%2C+Brooklyn%2C+NY+%28The+River+Cafe%29+%4040.703684%2C-73.994861\u0026iwstate1\u003ddir%3Ato",
                "ddUrlFromHere": "http://www.google.com/maps?source\u003duds\u0026saddr\u003d1+Water+Street%2C+Brooklyn%2C+NY+%28The+River+Cafe%29+%4040.703684%2C-73.994861\u0026iwstate1\u003ddir%3Afrom",
                "streetAddress": "1 Water Street",
                "city": "Brooklyn",
                "region": "NY",
                "country": "United States",
                "staticMapUrl": "http://mt.google.com/mapdata?cc\u003dus\u0026tstyp\u003d5\u0026Point\u003db\u0026Point.latitude_e6\u003d40703684\u0026Point.longitude_e6\u003d-73994861\u0026Point.iconid\u003d15\u0026Point\u003de\u0026w\u003d150\u0026h\u003d100\u0026zl\u003d4",
                "url": "http://www.google.com/maps/place?source\u003duds\u0026q\u003drestaurants\u0026cid\u003d9181090609208620883",
                "content": "",
                "maxAge": 604800,
                "phoneNumbers": [
                    {
                        "type": "",
                        "number": "(718) 522-5200"
                    }
                ],
                "addressLines": [
                    "1 Water Street",
                    "Brooklyn, NY"
                ]
            },
            {
                "GsearchResultClass": "GlocalSearch",
                "viewportmode": "explicit",
                "listingType": "local",
                "lat": "40.702956",
                "lng": "-73.994105",
                "accuracy": "8",
                "title": "Pete\u0026#39;s Downtown \u003cb\u003eRestaurant\u003c/b\u003e",
                "titleNoFormatting": "Pete's Downtown Restaurant",
                "ddUrl": "http://www.google.com/maps?source\u003duds\u0026daddr\u003d1+Cadman+Plaza+West%2C+Brooklyn%2C+NY+%28Pete%27s+Downtown+Restaurant%29+%4040.702956%2C-73.994105\u0026saddr\u003d40.70%2C-74.00",
                "ddUrlToHere": "http://www.google.com/maps?source\u003duds\u0026daddr\u003d1+Cadman+Plaza+West%2C+Brooklyn%2C+NY+%28Pete%27s+Downtown+Restaurant%29+%4040.702956%2C-73.994105\u0026iwstate1\u003ddir%3Ato",
                "ddUrlFromHere": "http://www.google.com/maps?source\u003duds\u0026saddr\u003d1+Cadman+Plaza+West%2C+Brooklyn%2C+NY+%28Pete%27s+Downtown+Restaurant%29+%4040.702956%2C-73.994105\u0026iwstate1\u003ddir%3Afrom",
                "streetAddress": "1 Cadman Plaza West",
                "city": "Brooklyn",
                "region": "NY",
                "country": "United States",
                "staticMapUrl": "http://mt.google.com/mapdata?cc\u003dus\u0026tstyp\u003d5\u0026Point\u003db\u0026Point.latitude_e6\u003d40702956\u0026Point.longitude_e6\u003d-73994105\u0026Point.iconid\u003d15\u0026Point\u003de\u0026w\u003d150\u0026h\u003d100\u0026zl\u003d4",
                "url": "http://www.google.com/maps/place?source\u003duds\u0026q\u003drestaurants\u0026cid\u003d4933341782274549162",
                "content": "",
                "maxAge": 604800,
                "phoneNumbers": [
                    {
                        "type": "",
                        "number": "(718) 858-3510"
                    }
                ],
                "addressLines": [
                    "1 Cadman Plaza West",
                    "Brooklyn, NY"
                ]
            },
            {
                "GsearchResultClass": "GlocalSearch",
                "viewportmode": "explicit",
                "listingType": "local",
                "lat": "40.702726",
                "lng": "-73.993499",
                "accuracy": "8",
                "title": "Grimaldi\u0026#39;s Pizzeria",
                "titleNoFormatting": "Grimaldi's Pizzeria",
                "ddUrl": "http://www.google.com/maps?source\u003duds\u0026daddr\u003d19+Old+Fulton+St%2C+%2C+NY+%28Grimaldi%27s+Pizzeria%29+%4040.702726%2C-73.993499\u0026saddr\u003d40.70%2C-74.00",
                "ddUrlToHere": "http://www.google.com/maps?source\u003duds\u0026daddr\u003d19+Old+Fulton+St%2C+%2C+NY+%28Grimaldi%27s+Pizzeria%29+%4040.702726%2C-73.993499\u0026iwstate1\u003ddir%3Ato",
                "ddUrlFromHere": "http://www.google.com/maps?source\u003duds\u0026saddr\u003d19+Old+Fulton+St%2C+%2C+NY+%28Grimaldi%27s+Pizzeria%29+%4040.702726%2C-73.993499\u0026iwstate1\u003ddir%3Afrom",
                "streetAddress": "19 Old Fulton St",
                "city": "",
                "region": "NY",
                "country": "United States",
                "staticMapUrl": "http://mt.google.com/mapdata?cc\u003dus\u0026tstyp\u003d5\u0026Point\u003db\u0026Point.latitude_e6\u003d40702726\u0026Point.longitude_e6\u003d-73993499\u0026Point.iconid\u003d15\u0026Point\u003de\u0026w\u003d150\u0026h\u003d100\u0026zl\u003d4",
                "url": "http://www.google.com/maps/place?source\u003duds\u0026q\u003drestaurants\u0026cid\u003d4244157563901397553",
                "content": "",
                "maxAge": 604800,
                "phoneNumbers": [
                    {
                        "type": "",
                        "number": "(718) 858-4300"
                    }
                ],
                "addressLines": [
                    "19 Old Fulton St",
                    "Brooklyn, NY"
                ]
            },
            {
                "GsearchResultClass": "GlocalSearch",
                "viewportmode": "explicit",
                "listingType": "local",
                "lat": "40.695108",
                "lng": "-73.996252",
                "accuracy": "8",
                "title": "Teresa\u0026#39;s \u003cb\u003eRestaurant\u003c/b\u003e",
                "titleNoFormatting": "Teresa's Restaurant",
                "ddUrl": "http://www.google.com/maps?source\u003duds\u0026daddr\u003d80+Montague+Street%2C+Brooklyn%2C+NY+%28Teresa%27s+Restaurant%29+%4040.695108%2C-73.996252\u0026saddr\u003d40.70%2C-74.00",
                "ddUrlToHere": "http://www.google.com/maps?source\u003duds\u0026daddr\u003d80+Montague+Street%2C+Brooklyn%2C+NY+%28Teresa%27s+Restaurant%29+%4040.695108%2C-73.996252\u0026iwstate1\u003ddir%3Ato",
                "ddUrlFromHere": "http://www.google.com/maps?source\u003duds\u0026saddr\u003d80+Montague+Street%2C+Brooklyn%2C+NY+%28Teresa%27s+Restaurant%29+%4040.695108%2C-73.996252\u0026iwstate1\u003ddir%3Afrom",
                "streetAddress": "80 Montague Street",
                "city": "Brooklyn",
                "region": "NY",
                "country": "United States",
                "staticMapUrl": "http://mt.google.com/mapdata?cc\u003dus\u0026tstyp\u003d5\u0026Point\u003db\u0026Point.latitude_e6\u003d40695108\u0026Point.longitude_e6\u003d-73996252\u0026Point.iconid\u003d15\u0026Point\u003de\u0026w\u003d150\u0026h\u003d100\u0026zl\u003d4",
                "url": "http://www.google.com/maps/place?source\u003duds\u0026q\u003drestaurants\u0026cid\u003d12686375620276309855",
                "content": "",
                "maxAge": 604800,
                "phoneNumbers": [
                    {
                        "type": "",
                        "number": "(718) 797-3996"
                    }
                ],
                "addressLines": [
                    "80 Montague Street",
                    "Brooklyn, NY"
                ]
            }
        ],
        "cursor": {
            "pages": [
                {
                    "start": "0",
                    "label": 1
                },
                {
                    "start": "4",
                    "label": 2
                },
                {
                    "start": "8",
                    "label": 3
                },
                {
                    "start": "12",
                    "label": 4
                }
            ],
            "estimatedResultCount": "189307",
            "currentPageIndex": 0,
            "moreResultsUrl": "http://www.google.com/local?oe\u003dutf8\u0026ie\u003dutf8\u0026num\u003d4\u0026mrt\u003dyp%2Cloc\u0026sll\u003d37.779160%2C-122.420090\u0026start\u003d0\u0026hl\u003den\u0026q\u003drestaurants+40.70%2C-74.00"
        },
        "viewport": {
            "center": {
                "lat": "40.699396",
                "lng": "-73.99675"
            },
            "span": {
                "lat": "0.010291",
                "lng": "0.007801"
            },
            "sw": {
                "lat": "40.69425",
                "lng": "-74.00065"
            },
            "ne": {
                "lat": "40.70454",
                "lng": "-73.99285"
            }
        }
    },
    "responseDetails": null,
    "responseStatus": 200
}

演示Java,PHP,Python,Perl和Flash中API访问的Google AJAX Search API documentation provides some code snippets