📜 ⬆️ ⬇️

Google Places example

About the service


Having visited the Google Developer Day 2011 event, I found out about the new Google places service (in the Russian version of “Google Addresses”).
An interesting lecture about this was read by a colorful view by an employee of Mano Marks.
This service provides the ability to search for various objects (POIs) in the vicinity of a given point. I want to talk about an example of practical use of the service.

To search for objects, you must specify the types of interest from the list. Today there are 129 different types . So far, this rubricator leaves much to be desired. Some areas are presented in great detail - for example, food: (food, restaurant, café, bar), some are not at all - there is no “hotel” type. I think that this is a problem of growth.
The data is taken from the Google database, which can be replenished users. Adding objects free, moderated. They are added mainly by the owners of the respective companies. After confirming the right to enter information, you can add photos, videos, coupons, real-time updates, such as weekly special offers, to your company's place on the page.
The API of this service is presented as a web service or java-script library for Google Maps.
The following functions are implemented:

Also, adding reviews is possible.

To use the API, you must download the library:
maps.googleapis.com/maps/api/js?libraries=places&sensor=true_or_false"

Example search query code for Google Maps:
var pyrmont = new google.maps.LatLng(-33.8665433,151.1956316);

map = new google.maps.Map(document.getElementById('map'), {
mapTypeId: google.maps.MapTypeId.ROADMAP,
center: pyrmont,
zoom: 15
});

var request = {
location: pyrmont,
radius: '500',
types: ['store']
};

service = new google.maps.places.PlacesService(map);
service.search(request, callback);


pyrmont is the seat of the Australian office of Google, where, apparently, is the development of the service.
Respectively used in the examples.
As you can see, you can set the area using the center point and radius in meters.
callback - the name of the handler function (for example, show markers or icons of places on the map)

In this area, you will search for places of the desired type (you can use an array of types)
The server response is an array of objects.
PlaceResult with the following properties:
• Geometry.location latitude-longitude.
• icon: url of recommended icons for the type (for now, icons are not for all types, those that are too large - 71x71 p., So those who want to get a beautiful result p will have to draw or search for pictures)
• id: a unique identifier, used to summarize disparate information about a place, but not to get details
• name: Name
• rating rating based on user feedback 0-5.
• reference identifier for requesting detailed information, may vary
• types: array of types (["restaurant", "establishment"]). - the place can be tied to several types.
• proximity: short address (district - street - house)
')
Using reference you can get the details for the site:
var request = {
reference: 'place_reference'
};

service = new google.maps.places.PlacesService(map);
service.getDetails(request, callback);


The answer will be:
• address_components: Address components (country - region - subregion, etc.)
• formatted_address: formatted address as a string
• formatted_phone_number: Phone number in international format
• geometry: geo information:
o location latitude - longitude.
o viewport is the preferred part of the map when displaying this place (so far I have not found an object with the specified property).
• html_attributions: Description.
• icon: URL Icons.
• id: unique identifier
• international_phone_number Telephone number in international standard (+61 2 9374 4000).
• name: Name
• rating: Rating 0.0 to 5.0.
• reference
• types: Types
• url: the URL of the Google Place Page.
• proximity: Address.
• Website Web sat of the company.

Also, it is possible to check in, i.e. registration of their stay in this place.
As I understand it, this function is laid down “for the future” for integration with social services, mobile platforms and ranking of objects in search results. To the question about protection against “check in spam,” the speaker replied that there was none.

Sample code (available via web service):

POST maps.googleapis.com/maps/api/place/check-in/json?sensor=true_or_false&key=api_key HTTP/1.1

{
"reference": "place_reference"
}


Adding objects to the database using web service

POST maps.googleapis.com/maps/api/place/add/json?sensor=true_or_false&key=api_key HTTP/1.1
Host: maps.googleapis.com

{
"location": {
"lat": -33.8669710,
"lng": 151.1958750
},
"accuracy": 50,
"name": "Google Shoes!",
"types": ["shoe_store"],
"language": "en-AU"
}


Example of use on the site villarenters.ru


Without hesitation, I decided to apply the novelty on the site Villa Rent - villarenters.ru , a site for searching proposals for renting houses, villas, apartment apartments.
When choosing an object for rent, especially for a long time, those who want to rent often have questions about the availability of a particular infrastructure in the vicinity.
To help with this issue, Google Places is very suitable. Let not all the information is well filled yet - it is a matter of time.
To implement the search next to the existing map on the information page of the villa posted a form of choosing the type of place. You can also specify the desired search radius in the form.
As an example, you can see the apartment page in Madrid (http://villarenters.ru/villa/30112.html#map-bar).
Select, for example, “bar” and a radius of 1 km, click “Show”.
Icons of the nearest bars will be displayed on the map. When you click on the icon, an information window is displayed with a link to the place page (opens in a new window).
When changing the viewing radius, it was necessary to force the zooming of the map - there is no automatic area detection. Accordingly, for different situations the display may not be correct (too many icons at one point or getting out of sight). Here you can only advise to use the manual zoom (±) on the left side of the card.

Conclusion


It can be assumed that Google places will be claimed by developers of mobile applications, especially social ones. You can imagine the integration with various databases (auto navigation, photos, custom POI)
I must say that in some moments there is an intersection with other services, in particular, Google maps displays some objects on maps by default. Registration of the stay is implemented through third-party applications, etc.
In general, we can say that the service is still damp, but it may already be useful in some cases.
I will be happy to answer questions and more light on those. implementation issues.

Source: https://habr.com/ru/post/132225/


All Articles