项目作者: nfriaa

项目描述 :
Ionic tutorial2 : Ionic Native (exemples de fonctionnalités natives : géolocalisation, ...)
高级语言: TypeScript
项目地址: git://github.com/nfriaa/ionic-tutorial2.git
创建时间: 2017-11-14T19:10:53Z
项目社区:https://github.com/nfriaa/ionic-tutorial2

开源协议:MIT License

下载


ionic-tutorial2

Ionic tutorial2 : Ionic Native (exemples de fonctionnalités natives : géolocalisation, …)

contributions welcome Travis license






Pour tester cette application en local

  1. git clone https://github.com/nfriaa/ionic-tutorial2.git
  2. cd ionic-tutorial2
  3. npm install
  4. ionic serve

Créer une nouvelle application Ionic

  1. ionic start ionic-tutorial2 sidemenu
  2. # puis démarrer dans le navigateur :
  3. ionic serve

1. La géolocalisation

  • ajouter une page pour tester la fonctionnalité de géolocalisation :

    1. ionic generate page Exemple1
  • ajouter les plugins suivants au projet :

    1. # ajouter Ionic Native à l'application :
    2. npm install @ionic-native/core --save
    3. # ajouter le plugin de géolocalisation :
    4. npm install @ionic-native/geolocation --save
  • ajouter la page Exemple1 au menu principal de l’application : (voir ionic-tutorial1).

  • dans le fichier src/app/app.module.ts :
    ```ts
    // ajouter l’import :
    import { Geolocation } from “@ionic-native/geolocation”;

// ajouter dans le tableau ‘providers’ :
providers: [
… ,
Geolocation
]

  1. - dans le fichier `src/pages/exemple1.ts` :
  2. ```ts
  3. // ajouter l'import :
  4. import { Geolocation } from "@ionic-native/geolocation";
  5. import { Platform } from "ionic-angular";
  6. // le code de la classe :
  7. export class Exemple1Page {
  8. myCurrentLatitude: number;
  9. myCurrentLongitude: number;
  10. constructor(
  11. public navCtrl: NavController,
  12. private platform: Platform,
  13. private geolocation: Geolocation
  14. ) {
  15. console.log("AboutPage Constructor");
  16. platform.ready().then(() => {
  17. // get current position
  18. geolocation.getCurrentPosition().then(pos => {
  19. console.log("lat: " + pos.coords.latitude + ", lon: " + pos.coords.longitude );
  20. this.myCurrentLatitude = pos.coords.latitude;
  21. this.myCurrentLongitude = pos.coords.longitude;
  22. });
  23. /*const watch = geolocation.watchPosition().subscribe(pos => {
  24. console.log("lat: " + pos.coords.latitude + ", lon: " + pos.coords.longitude);
  25. this.myCurrentLatitude = pos.coords.latitude;
  26. this.myCurrentLongitude = pos.coords.longitude;
  27. });*/
  28. // to stop watching
  29. //watch.unsubscribe();
  30. });
  31. }
  32. }
  • dans le fichier src/pages/exemple1/exemple1.html :
    ```html


    ma position actuelle : {{myCurrentLatitude}}, {{myCurrentLongitude}}


```