i’m click on a function for navigation and nearbyPlace() function call into the ionViewWillEnter like this.showing an error.
actually i want to do after click on a button the goring to next page and load the function nearbyPlace and showing near by location into the map.
ionViewWillEnter(){
this.nearbyPlace();
}
please help me anyone.
try to call that function in constructor
i have try but showing save error.
below my code
Home.ts
find(event) {
this.isType = event.target.value;
alert(this.isType);
this.navCtrl.push(MapPage,{
isType:this.isType
})
}
map.ts
export class MapPage {
@ViewChild('map')
mapElement: ElementRef;
map:any;
latLng:any;
markers:any;
mapOptions:any;
isKM:any=500;
isType:any="";
constructor(public navCtrl: NavController,private ngZone: NgZone, private geolocation : Geolocation,public navParams: NavParams) {
this.isType= navParams.get('isType');
}
ionViewDidLoad() {
this.loadMap();
}
ionViewWillEnter(){
this.nearbyPlace();
}
loadMap(){
this.geolocation.getCurrentPosition().then((position) => {
this.latLng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
//alert(this.latLng)
this.mapOptions = {
center: this.latLng,
zoom: 14,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
this.map = new google.maps.Map(this.mapElement.nativeElement, this.mapOptions);
}, (err) => {
alert('err '+err);
});
}
/*-----------------Find Nearby Place------------------------*/
nearbyPlace() {
//alert(this.LatLng)
alert(this.isKM);
alert(this.isType);
this.loadMap();
this.markers = [];
let service = new google.maps.places.PlacesService(this.map);
service.nearbySearch({
location: this.latLng,
radius: this.isKM,
types: [this.isType]
}, (results, status) => {
this.callback(results, status);
});
}
callback(results, status) {
if (status === google.maps.places.PlacesServiceStatus.OK) {
for (var i = 0; i < results.length; i++) {
this.createMarker(results[i]);
}
}
}
createMarker(place){
var placeLoc = place;
console.log('placeLoc',placeLoc)
this.markers = new google.maps.Marker({
map: this.map,
position: place.geometry.location
});
let infowindow = new google.maps.InfoWindow();
google.maps.event.addListener(this.markers, 'click', () => {
this.ngZone.run(() => {
infowindow.setContent(place.name);
infowindow.open(this.map, this.markers);
});
});
}