欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

A tutorial for Place search using G-map and OS-map APIs

程序员文章站 2022-03-13 22:05:26
...

Tutorials for Google APIs

Created on Feb.19, 2020. @author: Kai Shen, aaa@qq.com

What are Google Maps APIs?

Google places API allows developers to access a wealth of information from Google’s database for over 100 million places including location data, contact information, user ratings and reviews and more.

In this guide we will learn how to collect place information from Google Maps services. Compared with OpenStreetMap, one of the advantages of Google Maps service is the detailed query results, such as ratings, number of reviews, price level, etc. Based on this information, you can evaluate the “popularity” and “quality” of each place based on your own definition.

How to apply a Google Maps API key

A tutorial for Place search using G-map and OS-map APIs

P.s.

  1. By creating an account, you will be given a free 300$ credit to be used for these services which will be expired one year later. Regardless of the situation though, you still need to enter your credit card details for the Maps API to work with your API key.

  2. Warning: DO NOT CLICK on upgrade to paid account in Google Cloud Platform or you will lose your free amount of usage;

  3. In step 2, you have to create and name a project for which you want to use the APIs.

You have to initiate the API key authentication before accessing the API services. For more detailed explanation, please refer to: Google PLace API documentations

Places search functionalities provided by Google

Suppose you have an area (e.g. multiple regions in Kyoto city) on the map described by geographical coordinates (longitude and latitude), you want to pass this pair of coordinates to google API and get places of interest within this area.

Currently in the APIs in Python supported by Google, there is not yet a functionality to pass a special set of coordinates to a “Search box” to initiate automatic search for the whole area. Thus, we currently adopt the Nearby Search for getting places of interest in a specific region.

To get the complete results of an area, we perform a Nearby Search at the same point as the center of the area, and set the search radius to half the diagonal length of the area. Remember that the search circle defined by the search radius should be large enough to cover the entire area.

A tutorial for Place search using G-map and OS-map APIs

Before initiating Nearby Search API

Here is something you need to know. There is a limitation in the number of results returned by each query to Google Map API service:

A Text Search or a Nearby Search request would let you access directly the response parameters you need, but with one major restriction : they will return a maximum of 20 results per query. Each search can return as many as 60 results, split across three pages, which means that you can call a next_page_token data and get a grand total of 60 results, but then you are stuck.

Therefore, in order to parse the complete POI data from a larger area (such as the attraction areas defined in the Kyoto tourism survey data), I recommend first dividing the area into smaller grids and starting Nearby Search. To do so, in the Examples.py we implemented this with a method region_query() which automatically recursively divide into smaller areas to continue searching when the number of returned results reaches the limit.

A tutorial for Place search using G-map and OS-map APIs
Now you can go into the codes. Please refer to the annotations and comments in manuscripts for more information as well.

A preview of the query results.

They are sent back in json format and can be further parsed into key-value pairs, e.g.dict data structure in Python.

Res = 
{'geometry': {'location': {'lat': 34.97277770000001, 'lng': 135.690642},
                    'viewport': {'northeast': {'lat': 34.97420002989273,
                                               'lng': 135.6919653798927},
                                 'southwest': {'lat': 34.97150037010729, 'lng': 135.6892657201072}}},
       'icon': 'https://maps.gstatic.com/mapfiles/place_api/icons/restaurant-71.png',
       'id': '200310bbfaf7006dcdc2144f88902ad925d30aca',
       'name': '広島のお好み焼き工房三好',
       'opening_hours': {'open_now': True},
       'photos': [{'height': 3024,
                   'html_attributions': [
                       '<a href="https://maps.google.com/maps/contrib/107412752752099297772">yuri</a>'],
                   'photo_reference': 'CmRaAAAAV3TJ8OJc6lg8VYzYrBjcPi_KoCVFltX5R0-sKODuF4cBupOZG0s_OLTaF3X7onLTNAwVpNY8xG2FPXqeV812U5Xn2DmWJzQ0lXgK9plMgXgs-Vh37NwMsQYBHU6AN1soEhBXS-zdcndtBaOqTuucImCWGhQ1nt8xMsCZZfQH8S8jOIj0dg_ltg',
                   'width': 4032}],
       'place_id': 'ChIJp45CiMMGAWARsT-kSqn5rb4',
       'plus_code': {'compound_code': 'XMFR+47 Kyoto', 'global_code': '8Q6QXMFR+47'},
       'price_level': 2,
       'rating': 4.4,
       'reference': 'ChIJp45CiMMGAWARsT-kSqn5rb4',
       'scope': 'GOOGLE',
       'types': ['restaurant', 'food', 'point_of_interest', 'establishment'],
       'user_ratings_total': 106,
       'vicinity': '8-1 Katagiharanakakaito, Nishikyo Ward, Kyoto'}
       

Tutorials for OpenStreetMap APIs

Why OpenStreetMap?

OSM is a free editable map of the whole world. OpenStreetMap is built by a community of mappers that contribute and maintain data. As such, OpenStreetMap provides the following key features:

  • Local Knowledge
  • Community Driven
  • Open Data

There is no doubt that Google Maps have better coverage, more data with better quality, but you will also be charged quite a lot if you generate tons of inquires. Thus, in case you want to parse places in a large region, e.g. the whole Kyoto city while detailed place information is not of your interest (only want to know the rough number of places), then OSM is a better choice in that it provides comparatively free usage.

There are more ways for accessing and parsing places from OSM APIs. You can refer to following links or find more yourself.


Comments:

  • Can’t find coordinates of the area you want to search places from?

    • Go to OpenStreetMap, Click Export (on the left top), -> manually select a different area, then you see the coordinates of the boundary which can be defined by yourself.
  • Why did I use place search?
    In my case, I used place search to collect POIs in each attraction area.Specifically, in Gourmet dimension: I parsed:
    ○ Number of restaurants, bars and pubs (using OSM API)
    ○ High-end restaurants1 (using Google maps API)
    In Leisure dimension, I parsed
    ○ Shops and museums


b. Extract trip properties

This guideline introduces a
For more, refer to: Google maps API documentations
• Google direction API
• Google distance matrix API

• Time periods: 7:30 10:00 12:30 15:00 17:30 20:00
• Travel modes: "driving", "walking", "transit" or "bicycling"

Travel distance matrix;
Travel time
Transit fare matrix

• How to handle the travel cost in transit trips?
	○ i.e. One-day pass for bus travel

↑ though the cost may be similar (600 and 230 per travel * average 3~4 travels)

Users of the standard API:
• 2,500 free elements per day
• 100 elements per query
• 100 elements per 10 seconds

-------- To do --------
Trip utilites saved in folder ‘Final’

Trip utilities between several highway (Kyoto station) entrances to each destination.

Illustrate each area’s attractiveness with 3 circles of which the radius represent utilities respectively

Notes:
• Cycling not supported… not available in Japan… --> calculated with reference to walking time and distance
↑ calculate bicycling by referring walking time divided by speed ratio

Note: distance matrix API returned unstable and out-dated results for mode: Transit. Therefore in my master’s research, I calculated the edge database by utilizing the direction API iteratively.


  1. Price level at 3~4; ↩︎

相关标签: google