Getting location by Wifi or Cellular Corona sdk

I have a big problem with this and I’m little annoyed by how much informations about this getUserLocation() i have found, and none of it worked. All i need is to get longtitude and latitude by cellular or wifi, nothing else, if there is any other way than getUserLocation, I’m OK with that.

When i run this in my phone it says  Current location is unknown.

myMap = native.newMapView( 20, 20, 300, 220 ) function callMap() if(myMap ~= nil) then local currentLocation = myMap:getUserLocation() if currentLocation.errorCode ~= nil then native.showAlert("Jeeez it doesnt work again",currentLocation.errorMessage, {"OK"}) else native.showAlert("errorCode is nil which is good","...", {"OK"}) end else native.showAlert("Map is nil","...", {"OK"}) end end timer.performWithDelay( 3000, callMap )  

If you can make your app run in background you can do this. But somehow corona doesn’t support background state apps. anyways im finding other ways to do this. you can do this by, once your app recognise an wifi connection, your function for getting your location will trigger thus, making your location be known.

You need to access the GPS features to get the latitude and longitude.   See:
 

http://docs.coronalabs.com/api/event/location/index.html

Also, if you read the documents for getUserLocation() you will see that it can fail for several reasons:

http://docs.coronalabs.com/api/type/Map/getUserLocation.html

  • Current location has not been received yet.
  • Current location tracking is not available on the device.
  • The application does not have permission.

If you get a nil location, you might want to set a timer to check again in a few seconds.  It takes time for the GPS to come up.

Rob

If you can make your app run in background you can do this. But somehow corona doesn’t support background state apps. anyways im finding other ways to do this. you can do this by, once your app recognise an wifi connection, your function for getting your location will trigger thus, making your location be known.

You need to access the GPS features to get the latitude and longitude.   See:
 

http://docs.coronalabs.com/api/event/location/index.html

Also, if you read the documents for getUserLocation() you will see that it can fail for several reasons:

http://docs.coronalabs.com/api/type/Map/getUserLocation.html

  • Current location has not been received yet.
  • Current location tracking is not available on the device.
  • The application does not have permission.

If you get a nil location, you might want to set a timer to check again in a few seconds.  It takes time for the GPS to come up.

Rob