Socket
Socket
Sign inDemoInstall

pg-geolocation

Package Overview
Dependencies
0
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    pg-geolocation

Get current location in android & ios mobile app


Version published
Maintainers
1
Created

Readme

Source

Cordova Plugin Geolocation

Get current location in android & ios mobile app

Example

Installing the Cordova CLI

npm install -g cordova

Create the App

cordova create hello com.example.hello HelloWorld
cd hello

Add Platforms

cordova platform add ios
cordova platform add android

Add plugin

cordova plugin add pg-geolocation
cordova plugin add cordova-plugin-add-swift-support --save

For IOS

  • Open Xcode & choose team in signing
  • Build Phases > Link Binary With Libraries ==> Add CoreLocation.framework

  • Edit HelloWorld-Info.plist
  • Add privacy location permision

  • Change hello\www\js\index.js
  • Replace onDeviceReady function
onDeviceReady: function() {

  app.receivedEvent('deviceready');

  geolocation.getgeolocation(
    'Geolocation',
    function(msg) {
      document.getElementById('lat').innerHTML = msg[0].lat;
      document.getElementById('lng').innerHTML = msg[1].lng;
    },
    function(err) {
      document.getElementById('lat').innerHTML = err;
    }
  );

  geolocation.getstatus(
    'Plugin Ready',
    function(msg) {
      document.getElementById('deviceready').querySelector('.received').innerHTML = msg;
    },
    function(err) {
      document.getElementById('deviceready').innerHTML = '<p class="event received">' + err + '</p>';
    }
  );

  geolocation.getname(
    'Geolocation plugin',
    function(msg) {
      document.getElementsByTagName('h1')[0].innerHTML = msg;
    },
    function(err) {
      document.getElementsByTagName('h1')[0].innerHTML = err;
    }
  );
},
  • Change hello\www\index.html
<div class="app">
    <h1>Apache Cordova</h1>
    <div id="deviceready" class="blink">
        <p class="event listening">Connecting to Device</p>
        <p class="event received">Device is Ready</p>
    </div>
    <div class="">
      <p>Latitude: <span id="lat"></span></p>
      <p>Longitude: <span id="lng"></span></p>
    </div>
</div>

Build app

cordova build ios

Run app in Xcode

For Android

...

Keywords

FAQs

Last updated on 08 Oct 2017

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc