You need to sign in to do that
Don't have an account?

How to get GeoLocation in a lightning component?
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:
"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:
({ 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.
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
var latit = position.coords.latitude;
var longit = position.coords.longitude;
component.set("v.latit",latit);
component.set("v.longit",longit);
});
}