Geolocation Using Ionic Cordova Returning Incorrect Lat/Long Values

Mufaddal

I am facing issue using Geolocation pluggin with Ionic and Cordova framework.

Using Visual Studio Community 2015, with Cordova CLI version :4.3.0 and added the org.apache.cordova.geolocation pluggin to VSC-2015

My controller.js

.controller('MapCtrl', function ($scope) {  
function onSuccess(position) {            
        console.log(position.timestamp);
        console.log(position.coords.latitude + " " + position.coords.longitude);
    }
    function onError(error) {
        alert('code: ' + error.code + '\n' +
              'message: ' + error.message + '\n');
    }
    navigator.geolocation.getCurrentPosition(onSuccess, onError);


 })

Added the google maps into the index.html

<script src="https://maps.googleapis.com/maps/api/js?sensor=true&v=3.exp"></script> 

Added a Map to my Map.html file

<div id="map" data-tap-disabled="true" map> </div>

The problem is I always get a fixed value of Lat/Long ie Lat = 43.465187 and Long = -80.522372

This is not my correct Geolocation in terms of Lat/Long.I need my current Geolocation in terms of Lat/Long

Please help me identity the fault.

Also I am using Ripple -Nexus (Galaxy) on Browser.

Any help is appreciated... Thanks,

Mufaddal

Download the Latest version of GeoLocation pluggin from https://github.com/apache/cordova-plugin-geolocation

Then inject the $cordovaGeolocation into the controller. Code is as below:

.controller('HomeCtrl', function($scope,$cordovaGeolocation) {
$scope.getLocation = function() {      
  var posOptions = {timeout: 10000, enableHighAccuracy: false};
    $cordovaGeolocation
      .getCurrentPosition(posOptions)
      .then(function (position) {
        //these are your your lat long values  
        var lat  = position.coords.latitude
        var long = position.coords.longitude                        
        }, function(err) {
        // error           
       });
      }
    })

Note: The device need to be connected to internet or wifi and also need to keep the GPS location ON in the device for getting the correct Lat/Long Values.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

iOS Simulator allow cordova geolocation, using ionic framework

From Dev

glReadPixels returning incorrect values

From Dev

FindNext returning incorrect values

From Dev

FindNext returning incorrect values

From Dev

Methods returning incorrect values

From Dev

MACD Function Returning Incorrect Values

From Dev

Javascript calculator returning incorrect values

From Dev

trig functions returning incorrect values

From Dev

Java method returning incorrect values

From Dev

My code returning incorrect values

From Dev

How to add a marker in an Ionic App with the Cordova Geolocation plugin

From Dev

C++ atoi returning incorrect values

From Dev

Boolean array returning incorrect values from bitmask?

From Dev

Using plugins with cordova/ionic framework

From Dev

Using Ionic Material with Ionic and Cordova 5

From Dev

Setting NSLocationWhenInUseUsageDescription value when using cordova-plugin-geolocation

From Dev

Visual Studio 2015 Using Incorrect Cordova Version

From Dev

Cordova/Phonegap Geolocation

From Dev

Cordova geolocation watchPosition sensitivity

From Dev

Ionic: background geolocation

From Dev

Watch resume event on cordova using ionic framework

From Dev

Cordova plugins in Ionic 1 app using Typescript

From Dev

Ionic: Check Internet Connection using Cordova

From Dev

Using Cordova Plugins in Ionic Inside a Controller

From Dev

Java - HashMap.containsKey returning incorrect values for Objects

From Dev

Bing Maps geocoding REST service returning incorrect values

From Dev

Request Always Permission in Cordova Geolocation

From Dev

Geolocation not working in Cordova Android emulator

From Dev

Geolocation not working in Cordova Android emulator

Related Related

HotTag

Archive