Hello good day. I have an activity that needs to get my current location (latitude and longtitude). But every time I run my application, it sends me a different location. Can anyone help me? Thank you. Below is a sample of my code.
what you see is how the location sensor (gps) works. The LocationSensor always 'thinks' it is at 0 latitude, 0 longitude (it's default response) until the gps gets a satellite fix and determines a location based on the number of satellites it hears in the gps receiver. Sometimes, depending on your Android version and other factors it uses cell phone tower and WIFI information (if it is in its 'fused' mode). What is returned after a subsequent satellite fix is not necessarily the identical coordinates (although sometime it might be).
Have you read Using the Location Sensor . ? The tutorial explains how the LocationSensor works. Here is the documentation LocationSensor.
Does that explanation help?
Hello thank you for your help. But is my code correct? Or I am also missing something? Thank you
Your code appears correct but is over simplified. Whether it works as intended depends on what you expect it to do. It will provide a latitude, longitude pair. It will not place a Marker on your map, it will just show you the map that contains your location.