how to join two table in codeigniter easily[updated] | ci_model | ci_controller | codeigniter 3 -datainflow
Get Location Ionic
Now a days in maximum app want fetch location of user.So If you want get location in ionic 2 app follow the step.
Generate a New Ionic 2 Project
First, we will generate a new Ionic 2 project by running the following command:
ionic start get_geolocation blank
Now we install geolocation cordova plugin.
$ ionic plugin add cordova-plugin-geolocation
$ npm install --save @ionic-native/geolocation
Then import geolocation plugin.
import { Geolocation } from '@ionic-native/geolocation';
Add the Geolocation to provider in app module.
import { BrowserModule } from '@angular/platform-browser'; import { ErrorHandler, NgModule } from '@angular/core'; import { IonicApp, IonicModule } from 'ionic-angular'; import { SplashScreen } from '@ionic-native/splash-screen'; import { StatusBar } from '@ionic-native/status-bar'; import { MyApp } from './app.component'; import { HomePage } from '../pages/home/home'; import { Geolocation } from '@ionic-native/geolocation'; @NgModule({ declarations: [ MyApp, HomePage ], imports: [ BrowserModule, IonicModule.forRoot(MyApp) ], bootstrap: [IonicApp], entryComponents: [ MyApp, HomePage ], providers: [ Geolocation, StatusBar, SplashScreen, {provide: ErrorHandler, useClass: IonicErrorHandler} ] }) export class AppModule {}
Now import plugin to your .ts file at the top.
import { Geolocation } from '@ionic-native/geolocation';
constructor(private geolocation: Geolocation) { this.geolocation.getCurrentPosition().then((resp) => { var lat=resp.coords.latitude; var long=resp.coords.longitude; this.http.get('http://maps.googleapis.com/maps/api/geocode/json?latlng='+lat+','+long+'&sensor=true').map(res=>res.json()).subscribe(data => { var address = data.results[0]; this.location=address.formatted_address; }); }).catch((error) => { console.log('Error getting location', error); }); }
Related posts