i am trying to build a lightning component that shows nearby contacts based on the users current location. i am getting an error when trying to access the users current location through navigator.geoLocation. I get the following error. "Uncaught error in actionCallback : navigator.geoLocation is undefined"
Here is my component and its controller logic. Component:
<aura:component >
<aura:attribute name="latitude" type="Decimal"/>
<aura:attribute name="longitude" type="Decimal"/>
<aura:handler name="init" value="{!this}" action="{!c.doInit}" />
</aura:component>
Controller Logic:
({
doInit : function(component, event, helper) {
if(navigator.geoLocation){
console.log("capability is there");
}else{
console.log("No Capability");
}
navigator.geoLocation.getCurrentPosition(function(position){
this.latitude=component.set("v.latitude",position.coords.latitude);
this.longitude=component.set("v.longitude", position.coords.longitude);
console.log("Latitude is:"+this.latitude);
console.log("Longitude is:" +this.longitude);
});
}
})
debugging console log shows that my else part is only written to console. does that mean that geolocation is not supported in lightning? Am i doing anything wrong ? Any help would be appreciated.
Thanks in advance.