@justbe-angular/jb-google-location-api
v1.0.2
Published
google location api for justbe
Downloads
12
Readme
Justbe Google Location Api
Wrapper for google api services for justbe
Installation
Use the node package manager npm to install @justbe-angular/jb-google-location-api.
npm install @justbe-angular/jb-google-location-api --save
Usage
import JBGoogleLocationApiModule into your root module/app.module
import { NgModule } from '@angular/core';
import { JBGoogleLocationApiModule } from '@justbe-angular/jb-google-location-api';
@NgModule({
declarations: [
..
],
imports: [
..,
JBGoogleLocationApiModule,
..,
]
})
export class AppModule { }
configure JBGoogleLocationApiModule at entry point of your application
import { Component } from '@angular/core';
import { GoogleLocationApiService } from '@justbe-angular/jb-google-location-api';
@Component({
templateUrl: 'root.component.html'
})
export class RootComponent {
..
constructor(
..,
private googleLocationApiService: GoogleLocationApiService,
..
){}
this.googleLocationApiService.setConfigurations({
GOOGLE_API_KEY: 'your api key'
})
}
Search Places Around Your Location;
this method returns places arount you according to your search string it takes three argugments searchString Latitude Longitude and returns observable which resolve into list of places
import { GoogleLocationApiService } from '@justbe-angular/jb-google-location-api';
export class YourClass{
constructor(
..,
private googleLocationApiService: GoogleLocationApiService,
..,
){}
searchPlaces(){
this.googleLocationApiService.searchPlaces('janak baba', lat, lng).subscribe(res => {
if (res.status === 'OK') {
console.log(res.predictions);
}
})
}
}
Geocode;
this method will return latitude longitude from location. it takes one argugment adreessString.
import { GoogleLocationApiService } from '@justbe-angular/jb-google-location-api';
export class YourClass{
constructor(
..,
private googleLocationApiService: GoogleLocationApiService,
..,
){}
searchPlaces(){
this.googleLocationApiService.geocode(locationString).subscribe(res => {
if (res.status === 'OK') {
console.log(res.results);
}
})
}
}
Reverse Geocode;
this method will return location from latitude longitude. it takes two argugments Latitude Longitude.
import { GoogleLocationApiService } from '@justbe-angular/jb-google-location-api';
export class YourClass{
constructor(
..,
private googleLocationApiService: GoogleLocationApiService,
..,
){}
searchPlaces(){
this.googleLocationApiService.reverseGeocode(lat, lng).subscribe(res => {
if (res.status === 'OK') {
console.log(res.results);
}
})
}
}