Поиск достопримечательностей по приблизительному географическому положению - PullRequest
2 голосов
/ 28 февраля 2010

Мне было интересно, можно ли получить достопримечательности в месте на основе информации о широте / долготе или приблизительного адреса улицы, полученного из системы GPS? Интересные места в этом контексте определяются как: рестораны, курорты, парки, торговые центры, кинотеатры и т. д.

Существуют ли какие-либо онлайн-сервисы с картами bing / google maps / что-то еще, которые предоставляют такую ​​информацию в каком-то разобранном формате?

Спасибо

1 Ответ

4 голосов
/ 28 февраля 2010

На стороне клиента вы используете 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>

Результат будет следующим:

Результаты локального поиска 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
}

Документация API Google AJAX Search содержит некоторые фрагменты кода , демонстрирующие доступ к API в Java, PHP, Python, Perl и Flash.

...