I am working on angular 2 application with open layer map. in that i need to share the location coordinate from one components to other components.
one components
placesChanged() {
var places = this.searchBox.getPlaces();
if (places == null) return;
if (places == undefined) return;
if (places.length == 0) return;
this.searchResultsSource.clear();
this.bounds = new google.maps.LatLngBounds();
// For each place, get the icon, name and location.
places.forEach(this.processPlace.bind(this));
// if the drawn result(s) is only one
if (this.searchResultsSource.getFeatures().length == 1) {
var singleFeature = this.searchResultsSource.getFeatures()[0];
this.pos = singleFeature.getGeometry().getCoordinates();
console.log(this.pos);
}
this.animateView(places.length);
}
in this i am getting the pos value as geocoordinate and i want to share that pos value to other components.
other components
constructor(public dialogRef: MdDialogRef<BufferDialogComponent>,public searchcomponent: SearchComponent) {console.log(this.searchcomponent.pos);}
on pos i am getting error undefined. please help me.