Note that there are some explanatory texts on larger screens.

plurals
  1. POProblem in the MapActivity
    primarykey
    data
    text
    <p>i m testing an app that uses the google maps api. My app is working but my problem is:</p> <p>i want the gps to find my location and present it.If my gps in enabled,it wants some seconds to find my location.In these seconds, my app starts and uses the default long and lat..How could i add something like progress bar until my location found?thanks</p> <p>this is a part of my code:</p> <pre><code> private double locationLat=37.979116; private double locationLon=23.717766; MapView mapView; MapController mc; GeoPoint p; //.......... //in the onCreate LocationManager mlocManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE); LocationListener mlocListener = new MyLocationListener(); mlocManager.requestLocationUpdates( LocationManager.GPS_PROVIDER,0,0, mlocListener); MapView mapView = (MapView) findViewById(R.id.mapview); mapView.setBuiltInZoomControls(true); // mapView.setSatellite(true); // mapView.setStreetView(true); mc = mapView.getController(); String lata = String.valueOf(locationLat); String lnga = String.valueOf(locationLon); String coordinates[] = {lata, lnga}; double lat = Double.parseDouble(coordinates[0]); double lng = Double.parseDouble(coordinates[1]); p = new GeoPoint( (int) (lat * 1E6), (int) (lng * 1E6)); mc.animateTo(p); mc.setZoom(17); //---Add a location marker--- MapOverlay mapOverlay = new MapOverlay(); List&lt;Overlay&gt; listOfOverlays = mapView.getOverlays(); listOfOverlays.clear(); listOfOverlays.add(mapOverlay); mapView.invalidate(); //out of onCreate class MapOverlay extends com.google.android.maps.Overlay { @Override public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) { super.draw(canvas, mapView, shadow); //---translate the GeoPoint to screen pixels--- Point screenPts = new Point(); mapView.getProjection().toPixels(p, screenPts); //---add the marker--- Bitmap bmp = BitmapFactory.decodeResource( getResources(), R.drawable.avatar); canvas.drawBitmap(bmp, screenPts.x, screenPts.y-50, null); return true; } @Override public boolean onTouchEvent(MotionEvent event, MapView mapView) { //---when user lifts his finger--- if (event.getAction() == 1) { GeoPoint p = mapView.getProjection().fromPixels( (int) event.getX(), (int) event.getY()); Geocoder geoCoder = new Geocoder( getBaseContext(), Locale.getDefault()); try { List&lt;Address&gt; addresses = geoCoder.getFromLocation( p.getLatitudeE6() / 1E6, p.getLongitudeE6() / 1E6, 1); String add = ""; if (addresses.size() &gt; 0) { for (int i=0; i&lt;addresses.get(0).getMaxAddressLineIndex(); i++) add += addresses.get(0).getAddressLine(i) + "\n"; } Toast.makeText(getBaseContext(), add, Toast.LENGTH_SHORT).show(); } catch (IOException e) { e.printStackTrace(); } return true; } else return false; } } @Override protected boolean isRouteDisplayed() { return false; } /* Class My Location Listener */ public class MyLocationListener implements LocationListener { public void onLocationChanged(Location loc) { loc.getLatitude(); loc.getLongitude(); //String Text = "My current location is: " + //"Latitud = " + loc.getLatitude() + //"Longitud = " + loc.getLongitude(); locationLat=loc.getLatitude(); locationLon=loc.getLongitude(); // Toast.makeText( getApplicationContext(), // // Text, // // Toast.LENGTH_SHORT).show(); } public void onProviderDisabled(String provider) { Toast.makeText( getApplicationContext(), "Gps Disabled", Toast.LENGTH_SHORT ).show(); } public void onProviderEnabled(String provider) { Toast.makeText( getApplicationContext(), "Gps Enabled", Toast.LENGTH_SHORT).show(); } public void onStatusChanged(String provider, int status, Bundle extras) { } }/* End of Class MyLocationListener */ }/* End of Activity */ </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
 

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