How-TosUncategorized

Ionic 3 for Nearby Places

1*G13Ha tja3uAyINlhMIFrQ

In the process of developing an App, which has a feature of Nearby Places, I tried out Ionic 3 Native-Geolocation and Google Maps APIs. Lot of us, must be trying to do something like this in their App. Here in this story, I’ll try to explain you that.

To start with, install the dependencies and packages required.

First you need to install the Cordova Plugin for Geolocation.

You can refer to ionic documentation . (I’m using Ionic 3)

ionic cordova plugin add cordova-plugin-geolocation — variable GEOLOCATION_USAGE_DESCRIPTION=”To locate you”

Then install the Package :

npm install — save @ionic-native/geolocation@4

Add this plugin to your app.module.ts file ::

import { Geolocation } from ‘@ionic-native/geolocation’;
providers: [

Geolocation,

]

Create a provider for the Location Service::
ionic generate provider locations

In location.ts, add the following code.

1*XlAJNn4nS2rJnoN4klMVSw
Code snippet of location.ts

Import location service to the page’s ts file you want to show the Map. (For me nearby.ts)

1*EXfyqPa923YfE95C1P4Irg
Code snippet of the .ts file

Now you have got the Latitude and Longitude of the current location. Now you need to call the loadMap() to initiate the map.

Here the nearbyCenters array holds all the Lat-Lng of the places I want to pin.

If you need to pin certain places, use Google Maps Geocode API to get the Lat-Lng of those address.

In HTML page, just add <div #map id=”map”></div>

Annnndddd.. its done..!!

Bonus TIP:: 
To test your App in real devices, let it be Android or iOS, download Ionic DevApp. Trust me, to know its benefits, try it yourself.

Follow step-by-step. And at any point if you are stuck or need any help in implementing this, feel free to contact me or even if any change/correction is required. Just drop a mail with your query at [email protected]

Rajesh Mishra

I'm a developer who loves sharing insights, technical how-tos, and lessons learned from the world of code. While much of what I write may not be groundbreaking, I believe in documenting for future me—and for anyone else who might find it useful. Beyond tech, I also dive into life's experiences and moments, reflecting on personal growth and sharing stories that resonate. Whether you're here for practical tips or a fresh perspective on life, I hope you find something meaningful.

Leave a Reply

Your email address will not be published. Required fields are marked *