Updating native map location on invisible map?

Below is the link to a topic I started some time ago. It regarded problems displaying the native map on an iPad, while working perfectly on iPhone. I now found out what the problem was: it seems that if the map is set isVisible = false, then the coordinates from map:getUserLocation() will always be zero. But only on iPad, on iPhone it works perfectly.

https://forums.coronalabs.com/topic/72171-native-map-view-is-blank/

I cannot find anything about this is the docs and before I ask Corona to update them, has anyone else encountered this little “quirk”…?

i’ve always had problems with native map from corona. to minimize the problems I always use a timer (try different values) to update my user location, and have 3 tries if it returns nil or 0. after that it gives up and show an alert that it can’t show its position.

That is exactly what I do too, but if the map is not visible, the location will never be set on iPad, only on iPhone.

did you tried events? last time i remember i used them to get my position not native map.

I just create a runtime and check if i get gps coordenates, if not, use same timers to try 3 times. (removing and creating the runtime again - Runtime:addEventListener( “location”, locationHandler ))

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

ex: 

https://docs.coronalabs.com/api/event/location/latitude.html

The thing is, if the map is invisible, then no coordinates are ever received on an iPad. Doesn’t matter if you use events or any other stuff, you will never get coordinates. On iPhone, it works well.

don’t know if you understood what i mean.

what i sugest is not use an invisible map. that’s the wrong aproach if you just want the user coordinates.

there are events for that, i just point you the way to get user coordenates without using an invisible map. never had problems with that, and i test all my projects in an old ipad we have. 100% working till now.

Sorry, my fault: the reason that the map is invisible at app start is that I first want to set the current location of the user before making the map visible. Otherwise, some default address in China (?) is displayed briefly until the users real coordinates are received and the map location updated.

that’ a normal behavior of a map, google maps does that or any other map as far as i know, the user is expecting that behavior. gps can take sometime to update user position.

delaying opening the map is worst than opening first the map then update the position. it makes your app looks slower than it is.

if map is not 100% of the screen you can show the user “updating user location” while it’s calculating to show user that is not the final position.

one trick that i use to get a faster location, is on main menu i create the event to get lat, lng. when i press the map button, i refresh the position, you can create the map with that positions, or use lat, lng if you don’t need the map. usually it will give me instant location with that aproach. if your app starts with the map, this will not work ofc.

I was also thinking about that last aproach but my app starts with a map view so that doesn’t work. Anyway, it’s not a big deal. Hopefully the users will not react negatively about the “false” address showed initially before the real location is fetched.

Thanks for your help!

i’ve always had problems with native map from corona. to minimize the problems I always use a timer (try different values) to update my user location, and have 3 tries if it returns nil or 0. after that it gives up and show an alert that it can’t show its position.

That is exactly what I do too, but if the map is not visible, the location will never be set on iPad, only on iPhone.

did you tried events? last time i remember i used them to get my position not native map.

I just create a runtime and check if i get gps coordenates, if not, use same timers to try 3 times. (removing and creating the runtime again - Runtime:addEventListener( “location”, locationHandler ))

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

ex: 

https://docs.coronalabs.com/api/event/location/latitude.html

The thing is, if the map is invisible, then no coordinates are ever received on an iPad. Doesn’t matter if you use events or any other stuff, you will never get coordinates. On iPhone, it works well.

don’t know if you understood what i mean.

what i sugest is not use an invisible map. that’s the wrong aproach if you just want the user coordinates.

there are events for that, i just point you the way to get user coordenates without using an invisible map. never had problems with that, and i test all my projects in an old ipad we have. 100% working till now.

Sorry, my fault: the reason that the map is invisible at app start is that I first want to set the current location of the user before making the map visible. Otherwise, some default address in China (?) is displayed briefly until the users real coordinates are received and the map location updated.

that’ a normal behavior of a map, google maps does that or any other map as far as i know, the user is expecting that behavior. gps can take sometime to update user position.

delaying opening the map is worst than opening first the map then update the position. it makes your app looks slower than it is.

if map is not 100% of the screen you can show the user “updating user location” while it’s calculating to show user that is not the final position.

one trick that i use to get a faster location, is on main menu i create the event to get lat, lng. when i press the map button, i refresh the position, you can create the map with that positions, or use lat, lng if you don’t need the map. usually it will give me instant location with that aproach. if your app starts with the map, this will not work ofc.

I was also thinking about that last aproach but my app starts with a map view so that doesn’t work. Anyway, it’s not a big deal. Hopefully the users will not react negatively about the “false” address showed initially before the real location is fetched.

Thanks for your help!