Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Initializing location?
Started by jbreed2012 Mar 03 2014 03:07 PM

6 replies to this topic
gps maps location geolocation
[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

jbreed2012

[GLOBAL: userInfoPane.html]
jbreed2012
  • Observer

  • 17 posts
  • Corona SDK

Hi,

 

     At this moment I have a section of my app on a timer to get current location. How can I pull this when the app loads to prevent having to wait several seconds to make sure it doesn't return an error? 



[TOPIC: post.html]
#2

FoxB

[GLOBAL: userInfoPane.html]
FoxB
  • Enthusiast

  • 37 posts
  • Corona SDK

o.O I do not understand your question, but I know A LOT ABOUT GPS so I hope I can help you as soon as I understand.



[TOPIC: post.html]
#3

jbreed2012

[GLOBAL: userInfoPane.html]
jbreed2012
  • Observer

  • 17 posts
  • Corona SDK

o.O I do not understand your question, but I know A LOT ABOUT GPS so I hope I can help you as soon as I understand.

 

Whenever a user goes to a section that pulls a database from parse based on location if I don't use a timer to hold off on running getlocation(), then it returns an error and fails. I was wondering if I could call getlocation() early to have it ready for when it goes to this lua file. Or, if I can have it connect and run a loading screen until it grabs the user location. Instead of setting a timer I tried having a runtime listener and removing it once the function starts, but I don't think it was removing properly because the map kept centering on the users location and kept pulling data. Would like to have a little loading icon to let the user know the app is actually doing something instead of them staring at a blank section until the data is pulled. Pulling from the database requires I have the lat/long first as well.

 

Code layout looks like this:

 

startfunction (getlocation -> grab database -> place markers)

 

timer (startfunction)



[TOPIC: post.html]
#4

jbreed2012

[GLOBAL: userInfoPane.html]
jbreed2012
  • Observer

  • 17 posts
  • Corona SDK

Also, how can I calculate the distance between two points. Don't need to sort since the database is retrieved already sorted and placed in a tableview, but need the distance in miles. I found documents for calculating meters and sorting, which you posted, but need miles.



[TOPIC: post.html]
#5

jbreed2012

[GLOBAL: userInfoPane.html]
jbreed2012
  • Observer

  • 17 posts
  • Corona SDK

Nevermind about the miles section. 

 

Here is what I have for getting the distance. I am pulling the marker geopoints from parse and printing information into a tableview. Parse returns them in order so I just had to add the formula to calc the distance to add that to the row in the table. 

 

 

centerPoint = {latitude = currentLatitude, longitude = currentLongitude}
 
 function distance(from, to)
      local radius =  3440.065
      local dLat = math.rad(from.latitude - to.latitude)
      local dLon = math.rad(from.longitude - to.longitude)
      local lat1 = math.rad(to.latitude)
      local lat2 = math.rad(from.latitude)
      local a = math.sin(dLat/2) * math.sin(dLat/2) + math.sin(dLon/2) * math.sin(dLon/2) * math.cos(lat1) * math.cos(lat2)
      local circle = 2*math.atan2(math.sqrt(a), math.sqrt(1-a))
      local distance = radius * circle
      return distance
 end
 
--In the for loop for parse geopoints
local marker = {latitude = lat, longitude = long}
local calculateddistance = distance(centerPoint, marker)



[TOPIC: post.html]
#6

FoxB

[GLOBAL: userInfoPane.html]
FoxB
  • Enthusiast

  • 37 posts
  • Corona SDK

Are you running the latest version of Corona? (Old versions don't have a default GPS coordinates support)

What error are you getting? (from event.error)

 

Also, be sure to first get the GPS coordinates before you pull any data from a database.

 

Will this help you?

http://code.coronalabs.com/tags/gps



[TOPIC: post.html]
#7

jbreed2012

[GLOBAL: userInfoPane.html]
jbreed2012
  • Observer

  • 17 posts
  • Corona SDK

Are you running the latest version of Corona? (Old versions don't have a default GPS coordinates support)

What error are you getting? (from event.error)

 

Also, be sure to first get the GPS coordinates before you pull any data from a database.

 

Will this help you?

http://code.coronalabs.com/tags/gps

If I don't have a timer and instantly pull I get 'location unknown' so I have a 5 second timer running to give the page time to pull location before running. 

 

 

I'll give this a shot: http://code.coronalabs.com/code/update-gps-every-x-seconds 




[topic_controls]
[/topic_controls]