Note that there are some explanatory texts on larger screens.

plurals
  1. POA few problems with maps and location listeners - Android
    primarykey
    data
    text
    <p>I have a few questions regarding the Google maps api and its usage etc. For a brief background on what I've done so far is that I've shown maps that are extending FragmentActivity while implementing OnMyLocationChangeListener and LocationListener. Then I've set the LocationManager and got my position from it. The map works fine. My position is also shown on the map with a blue marker and everything looks set...</p> <ol> <li><p>The problem is that my position is not updated when I run the app using GPRS/EDGE. I mean it gets updated but after a very long time (2 or 3 minutes) and even then the marker is misplaced by a few hundred meters and doesn't show my exact location. Why is this problem occurring? Is my GPRS/EDGE the problem? Would it "work fast"/"show correct location" on 3G?</p></li> <li><p>The second problem is that the OnLocationChanged(Location location) function is NEVER called. While the onMyLocationChange(Location location) is called EVERY TIME. Is this the correct behavior? Or should the OnLocationChanged(Location location) function be called as frequently as the onMyLocationChange(Location location) function?</p></li> <li><p>The third and the most important one to be addressed is that I have placed a few markers on my map and I need to calculate the distance of each marker from my position. Now when I move, the distances between me and all the markers change, I have implemented a loop for calculating distances and saving them in an array in the onMyLocationChange(Location location) function, but it is called so quickly again and again that the for loop doesn't execute at all. Is there an alternative where I can simply call these functions after (let's say) five seconds so while inside the five seconds the for loop gets executed properly and fully and my distance array gets populated.</p> <pre><code> FragmentManager myFragmentManager = getSupportFragmentManager(); SupportMapFragment mySupportMapFragment = (SupportMapFragment)myFragmentManager.findFragmentById(R.id.map); myMap = mySupportMapFragment.getMap(); locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); if(locationManager != null){ locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this); Location location = locationManager. getLastKnownLocation(LocationManager.NETWORK_PROVIDER); myPosition = new LatLng(location.getLatitude(), location.getLongitude()); } else { Toast toast = Toast.makeText(this, "Location manager is null", Toast.LENGTH_LONG); toast.show(); } myMap.setMyLocationEnabled(true); myMap.setOnMyLocationChangeListener(this); myMap.animateCamera(CameraUpdateFactory.newLatLngZoom(myPosition, 16)); public void onMyLocationChange(Location location) { myPosition = new LatLng(location.getLatitude(), location.getLongitude()); Toast toast = Toast.makeText(this, "This one is always called", Toast.LENGTH_LONG); toast.show(); } @Override public void onLocationChanged(Location location) { myPosition = new LatLng(location.getLatitude(), location.getLongitude()); Toast toast = Toast.makeText(this, "This one never gets called", Toast.LENGTH_LONG); toast.show(); } </code></pre></li> </ol>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload