Google Places Example

    About service


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

    To search for objects, you need to set the types of interest from the list. Today, there are 129 different types . So far, this heading 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 type of "hotel". I think that these are problems of growth.
    The data is taken from a Google database, which can be replenished by users. Adding objects is 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 page.
    The API of this service is presented as a web service or java-script library for Google Maps.
    The following functions are implemented:
    • 1. Search for places
    • 2. Getting detailed information about the place
    • 3. Registration of stay
    • 4. Adding a new place

    It is also possible to add reviews.

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

    An example of the search query code for Google Maps: pyrmont is the place of the Australian office of Google, where, apparently, the service is being developed. Accordingly 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, a search will be made for places of the desired type (you can use an array of types) The server response is an array consisting of PlaceResult objects with the following properties: • Geometry.location longitude-latitude .
    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);











    • icon: url of the recommended icon for the type (for now, the icons are not for all types, those that are too large - 71x71 p., So those who want to get a beautiful p result will have to draw or search for pictures)
    • id: a unique identifier used for generalization of diverse information about the place, but not for details
    • name: Name
    • rating rating based on user reviews 0-5.
    • reference identifier for requesting detailed information, may vary
    • types: array of types ([“restaurant”, “establishment”]). - A place can be tied to several types.
    • proximity: short address (district - street - house)

    Using reference you can get the details for the place: The answer will be:
    var request = {
    reference: 'place_reference'
    };

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



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

    Also, there is the possibility of check in, i.e. registration of your stay in this place.
    As I understand it, this function is laid "for the future" for integration with social services, mobile platforms and ranking objects in search results. When asked about protection against “check in spam,” the speaker answered that there is none.

    Sample code (available through the web service): Adding objects to the database using the 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"
    }




    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"
    }


    An example of use on the website villarenters.ru


    Without hesitation, I decided to apply the novelty on the site Rent villas - villarenters.ru , a site for searching proposals for renting houses, villas, apartment apartments.
    When choosing an object for rent, especially for a long time, people who want to rent often have questions about the availability of a particular infrastructure in the vicinity.
    To help with this issue, the Google Places service is very suitable. Even if information is not well filled everywhere, it is a matter of time.
    To implement the search, next to an existing map, on the villa information page, I placed a form for choosing the type of place. You can also specify the desired search radius in the form.
    As an example, you can see the page of the apartment in Madrid (http://villarenters.ru/villa/30112.html#map-bar).
    For example, select “bar” and a radius of 1 km, press “Show”.
    The map displays the icons of the nearest bars. 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 map to be zoomed in - there is no automatic definition of the area. Accordingly, for different situations, the display may not be correct (too many icons at one point or falling out of visibility). Here you can only advise using manual zoom (±) on the left side of the map.

    Conclusion


    It can be assumed that Google places will be in demand by developers of mobile applications, especially social ones. One can imagine integration with various databases (auto navigation, photos, custom POIs). I
    must say that at some points there is an intersection with other services, in particular, Google maps displays some objects on maps by default. Check-in 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 glad to answer questions and cover those in more detail. implementation issues.

    Also popular now: