简体   繁体   中英

how to get current location in three actions on phonegap

Hi I need to get current locations for my app on three types of page, I Have call separate functions for that three pages,

if click first page, then call first function and get current location,

I need that action on another two pages also, I mean like below structure,

function current_locations()
{
  //get locations and return as object;
}

First page call this function:

function first()
{
var loc = current_locations();
var lat=loc.latitude;
var lon=loc.longitude;
//some actions
}

second page call this function:

function second()
{
var loc = current_locations();
var lat=loc.latitude;
var lon=loc.longitude;
//some actions
}

third page call this function:

function third()
{
var loc = current_locations();
var lat=loc.latitude;
var lon=loc.longitude;
//some actions
}

Please help me, many time i am trying I can't get location value correctly.

Advance thanks

看一下GeolocalizaçaoAPI( https://github.com/apache/cordova-plugin-geolocation/blob/dev/doc/index.md ),您可以使用phonegap获取位置。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM