I have a search form in my homepage that has input box and select dropdown. The user can search other users either by typing the location or by html5 geolocation. So when user visits the page for first time, it asks user if they let app know their location. If they agree, then latitude longitude and selected option from dropdown is taken and run database query. However I am not sure if my following attempt is the way it should be. Since I also want to bind the select when user searches with or without geolocation. My select input is
<div class="input-group-btn">
<select class="btn btn-danger btn-lg" style="border-radius: 0px;" bindon-ngModel="btype" on-ngModelChange="search($event)" on-ngModelChange="successPosition($event)" name="btype" >
<option *ngFor="let btype of bloodtypes" [value]="btype">{{btype}}</option>
</select>
</div>
My geolocation function inside the angular2 component looks like this
geolocation: function(){
if(navigator.geolocation){
navigator.geolocation.getCurrentPosition(this.successPosition,
this.failurePosition, {
enableHighAccuracy: true,
timeout:3000,
maximumAge: 4000 });
}
else{
return(false);
}
},
successPosition: function(position){
if(position.coords.latitude && position.coords.longitude){
self.latitude = position.coords.latitude;
self.longitude = position.coords.longitude;
}else{
self.btype = position;
}
window.location.replace("/users?utf8=✓&longitude=" +
encodeURIComponent(self.longitude) + "&latitude=" +
encodeURIComponent(self.latitude) + "&btype=" +
encodeURIComponent(self.btype));
},
but when successPosition()
recieves the parameter I cannot assign latitude
, longitude
and btype
at the same time. If I assign latitude
and longitude
, btype
is undefined and vice versa. Please tell me is this how should I do or there is another method?