开发者

Finding places of interest, based on approx geo location

开发者 https://www.devze.com 2022-12-21 17:01 出处:网络
I was wondering if it is possible to get the places of interest in a location based on the lattitude/longi开发者_Go百科tude information or approximate street address gathered from a GPS system?

I was wondering if it is possible to get the places of interest in a location based on the lattitude/longi开发者_Go百科tude information or approximate street address gathered from a GPS system? places of interest are defined in this context as: Restaurants, Resorts, Parks, malls, movie theaters, etc.

Are there some online services either with bing maps / google maps / something else, that provides such information in some parsed format?

Thank you


On the client side, you use the Google AJAX Search API to search for places of interest around a specific coordinate:

<!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>

The result would be the following:

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


To get the same results from the server side in JSON format, you may want to check the following article:

  • Google AJAX Search API: Flash and other Non-Javascript Environment

Basically you would be able to issue a request to Google in the following format:

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

Which would return the following 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
}

The Google AJAX Search API documentation provides some code snippets that demonstrate API access in Java, PHP, Python, Perl and Flash.

0

精彩评论

暂无评论...
验证码 换一张
取 消