Guest User

Untitled

a guest
Sep 18th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. Argument of type '(coordinates: NativeGeocoderForwardResult) => void' is not
  2. assignable to parameter of type '(value: NativeGeocoderForwardResult[]) => void
  3. | PromiseLike<void>'.
  4.  
  5. import { Component, ViewChild, ElementRef } from '@angular/core';
  6. import { IonicPage, NavController, NavParams, AlertController } from 'ionic-angular';
  7. import leaflet from 'leaflet';
  8. import { NativeGeocoder, NativeGeocoderForwardResult } from '@ionic-native/native-geocoder';
  9.  
  10.  
  11. @IonicPage()
  12. @Component({
  13. selector: 'page-markermap',
  14. templateUrl: 'markermap.html',
  15. })
  16. export class MarkermapPage {
  17.  
  18. @ViewChild('map') mapContainer: ElementRef;
  19. map: any;
  20. constructor(public navCtrl: NavController, private alertCtrl: AlertController,private nativeGeocoder: NativeGeocoder) {
  21.  
  22. }
  23.  
  24. ionViewDidEnter() {
  25. this.loadmap();
  26. }
  27.  
  28. loadmap() {
  29. this.map = leaflet.map("map").fitWorld();
  30. leaflet.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
  31. attributions: 'www.tphangout.com',
  32. maxZoom: 14
  33. }).addTo(this.map);
  34. }
  35.  
  36. addMarker() {
  37. let prompt = this.alertCtrl.create({
  38. title: 'Add Marker',
  39. message: "Enter location",
  40. inputs: [
  41. {
  42. name: 'city',
  43. placeholder: 'City'
  44. },
  45. ],
  46. buttons: [
  47. {
  48. text: 'Cancel',
  49. handler: data => {
  50. console.log('Cancel clicked');
  51. }
  52. },
  53. {
  54. text: 'Save',
  55. handler: data => {
  56.  
  57. this.geoCodeandAdd(data.city);
  58. }
  59. }
  60. ]
  61. });
  62. prompt.present();
  63. }
  64.  
  65. geoCodeandAdd(city) {
  66. this.nativeGeocoder.forwardGeocode(city)
  67. .then((coordinates: NativeGeocoderForwardResult) => {
  68. let markerGroup = leaflet.featureGroup();
  69. let marker: any = leaflet.marker([coordinates[0].latitude, coordinates[0].longitude]).on('click', () => {
  70. alert('Marker clicked');
  71. })
  72. markerGroup.addLayer(marker);
  73. this.map.addLayer(markerGroup);
  74. })
  75. .catch((error: any) => console.log(error));
  76. }
  77.  
  78. }
Add Comment
Please, Sign In to add comment