How to get the current device location

191 views
Skip to first unread message

natanielt...@gmail.com

unread,
Nov 27, 2018, 7:53:33 AM11/27/18
to osmdroid

here is my code


Capturar.PNG


Frank Zeritsch

unread,
May 25, 2019, 3:43:13 PM5/25/19
to osmdroid
Firstly, I don't think** that you get your location updates out of osmdroid code.  I think you have to use other code available to your android.  Then when you have your lcation latitude and longitude, you can use in your osmdroid code.

I used the standard requestionLocationUpdate using android code, and it has worked well for me, but I'm switching over to FusedLocation API

Here is a good tutorial for FusedLocation


I suggest going to the end and copying the java text from his github source into your project, rather than follow perfectly, (His code snippets have a lot of redundancy that causes troubles...)  Then have a look at the tutorial to understand what does what,

I was able to get it all running on my phone in about 15 minutes  :)

Frank Zeritsch

unread,
May 25, 2019, 6:31:20 PM5/25/19
to osmdroid
I did a fair amount of googling to find the snippets which taught me how to use the Google API for android's Location Manager.  I couldn't find them easily..  That's why I started working with Fused Location from Google Play.  I will say though, I really like Fused Location.

Let me explain some pros and cons I've discovered.

Using the included android libraries for Google Location Manager, you do not need an internet connection.  It reads the GPS chip and gives you the coordinates.

Using the Fused Location, it connects to google servers and receives coordinates much faster (ironically). It DOES need an open internet connection all the time, but it uses a very small amount of phone data I believe.  It does use sensor data from other parts of your phone, and I feel the end result is super accurate.

The Google Location Manager doesn't give me anything useful in less that ~0.9 to 1.1 seconds. and the Fused is accurate in close to <0.5 secs.  Also, with the Google API, I found that my data wandered a bit.  My phone would be stationary, and yet it reported I was moving slightly around. I had to smooth my data to avoid that...  The Fused Library seemes to take care of the wandering.  I'm very pleased with that.

I'd like to pass on a concept I learned while working with GPS.  Maybe it can help others. 

You cannot get your exact location at you current time. EVER.  The GPS chip on your phone reports where you were in a previous amount of time (like 1 second).  That means when you ask 'where am I?' the code (any bit of code) tells you where you were a second ago.  In some cases, you will see a 'LastLocation' variable that your phone saved (so it seems like you got a fast result), but really it was the last saved position...

And when you ask for continuous updates, the request goes out, and then comes back reporting where you were when you requested the data, which could be several metres from where you are. That is why much of our coding for 'real time' display of position and triangulation etc, is compensating for a lag. Smart programming can make it seem negligible... But it's only hiding a 0.5-1.1 second lag. (values from my experiences and could vary),

Anyway.. hope I've helped... Have a great day!

Josileudo Rodrigues

unread,
May 28, 2019, 10:02:28 PM5/28/19
to osmd...@googlegroups.com
Olá, muito obrigado pela sua ajuda vou seguir sim seus concelhos, porém me explique uma coisa, como eu faria para utilizá-lo no osmdroid? Como faço para armazenar esses dados (Corrdenada, descrição, tempo) dentro de um SQLite? 

--
You received this message because you are subscribed to the Google Groups "osmdroid" group.
To unsubscribe from this group and stop receiving emails from it, send an email to osmdroid+u...@googlegroups.com.
Visit this group at https://groups.google.com/group/osmdroid.
To view this discussion on the web visit https://groups.google.com/d/msgid/osmdroid/15dd29ea-43a5-4871-9e3d-06a2929d9d9b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--

Reply all
Reply to author
Forward
0 new messages