Ionic 3 - Create a Nearby Restaurants App with Geolocation Plugin ,Google Maps and Places API Part 2

On the previous part we have added a map to our Ionic app then used the Cordova Geolocation plugin and its Ionic native 3.x+ wrapper to get current user position .

This tutorial has two parts :

Ionic 3 - Create a Nearby Restaurants App with Geolocation Plugin ,Google Maps and Places API

Ionic 3 - Create a Nearby Restaurants App with Geolocation Plugin ,Google Maps and Places API Part 2

On this part we are going to continue building our nearby restaurants mobile app so lets get started

First of all ,you need to change the script tag for including Google Maps JavaScript SDK in src/index.html to enable the Places API

<script src=""></script>

next open src/pages/home/home.scss and change to

page-home {
    .scroll {
        height: 100%

    #map {
        width: 100%;
        height: 40%;

So the maps takes only 40% in height .

Open src/pages/home/home.html an change it to :

    Nearby Me Restaurants

<ion-content padding>

<div #map id="map"></div> 

<div style="width : 100% ;height: 60%">
    <ion-item *ngFor="let place of places">


In src/pages/home/home.ts add a member variables of type Array to hold nearby places

declare var google;

selector: 'page-home',
templateUrl: 'home.html'
export class HomePage {
options : GeolocationOptions;
currentPos : Geoposition;
places : Array<any> ; 

Then add a getRestaurants() method to get the list of nearby restaurants

    var service = new google.maps.places.PlacesService(;
    let request = {
        location : latLng,
        radius : 8047 ,
        types: ["restaurant"]
    return new Promise((resolve,reject)=>{
            if(status === google.maps.places.PlacesServiceStatus.OK)



This method returns a promise which resolves to the list of restaurants or if there is an error it will be reject with the status code .

We have wrapped service.nearbySearch() method ,which uses callbacks ,in a Promise to play nice with Angular change detection .

Also add a createMarker() method

    let marker = new google.maps.Marker({
    animation: google.maps.Animation.DROP,
    position: place.geometry.location

This method creates a marker from a place .It's called for every place returned by PlacesService nearbySearch method .

Finally update the addMap() method to invoke the previous methods


    let latLng = new google.maps.LatLng(lat, long);

    let mapOptions = {
    center: latLng,
    zoom: 15,
    mapTypeId: google.maps.MapTypeId.ROADMAP
    } = new google.maps.Map(this.mapElement.nativeElement, mapOptions);

    this.getRestaurants(latLng).then((results : Array<any>)=>{
        this.places = results;
        for(let i = 0 ;i < results.length ; i++)



The variable this.places holds the list of nearby locations or restaurants which are then displayed using ion-list on the view .


That is it you have now created a nearby app with Ionic 3 which gets the current user location using the Cordova Geolocation plugin and Ionic Native then uses the Google Places API to search for nearby restaurants and display them in a Google Map and as a list of names .

comments powered by Disqus