Guest User

Untitled

a guest
May 22nd, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. import { Component , ViewChild, ElementRef} from '@angular/core';
  2. import { NavController } from 'ionic-angular';
  3. import {GoogleMap, GoogleMaps, LatLng, CameraPosition, GoogleMapsEvent , Marker, MarkerOptions } from '@ionic-native/google-maps';
  4. import {Geolocation} from '@ionic-native/geolocation';
  5.  
  6. @Component({
  7. selector: 'page-home',
  8. templateUrl: 'home.html'
  9. })
  10. export class HomePage {
  11. @ViewChild('map') mapelement : ElementRef;
  12. map : GoogleMap;
  13. initialMapLoad: boolean = true;
  14. constructor(public navCtrl: NavController, private _googlemap : GoogleMaps,
  15. private _geolocation : Geolocation) {
  16.  
  17. }
  18. ionViewDidLoad(){
  19.  
  20. this.initMap();
  21.  
  22. }
  23.  
  24.  
  25. initMap(){
  26. let element = this.mapelement.nativeElement;
  27. this.getlocation().then(res => {
  28. let loc = new LatLng(res.coords.latitude, res.coords.longitude);
  29. this.map = this._googlemap.create('map', {
  30. camera:{
  31. target: loc,
  32. zoom: 15
  33. }
  34.  
  35. });
  36. this.createmarker(loc, 'Me');
  37. }).catch (err => {
  38. console.log(err);
  39. });
  40.  
  41.  
  42. }
  43. ionViewDidEnter(){
  44. if (!this.initialMapLoad) {
  45. this.map.setDiv('map');
  46. } else {
  47. this.initialMapLoad = false;
  48. }
  49. }
  50. getlocation(){
  51. return this._geolocation.getCurrentPosition();
  52. }
  53. movecamer(loc : LatLng){
  54. let options : CameraPosition<LatLng> ={
  55. target: loc,
  56. zoom: 15,
  57. tilt: 10
  58. }
  59. this.map.moveCamera(options)
  60. }
  61. createmarker(loc: LatLng, title : string){
  62. let markeroptions : MarkerOptions = {
  63. position : loc,
  64. title : title
  65. }
  66. return this.map.addMarker(markeroptions);
  67. }
  68.  
  69. }
Add Comment
Please, Sign In to add comment