Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I display more points (GeoPoint) on a map?
    primarykey
    data
    text
    <p>Currently I am able to display one point the first point that I crated in the code(pointStatie), but I want to be displayed both points. I want to be displayed the point where I am located and another point that I passed the coordinates from another class.</p> <p>My current code is:</p> <pre><code>package aexp.elistcbox; import android.os.Bundle; import android.provider.SyncStateContract.Constants; import com.google.android.maps.MapActivity; import com.google.android.maps.MapView; import com.google.android.maps.MapController; import com.google.android.maps.GeoPoint; import android.content.Context; import android.content.Intent; import android.content.res.Resources; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; import android.location.Criteria; import android.util.Log; import android.widget.Toast; import android.location.Geocoder; import android.location.Address; import java.util.List; import java.util.Locale; import java.io.*; import com.google.android.maps.Overlay; import com.google.android.maps.OverlayItem; import android.graphics.Canvas; import android.graphics.Point; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.drawable.Drawable; public class GPSLocatorActivity extends MapActivity { public MapView mapView; public MapController mapController; public LocationManager locationManager; public LocationListener locationListener; public String best; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.map_view); mapView = (MapView) findViewById(R.id.mapView); mapView.setSatellite(false); mapView.setBuiltInZoomControls(true); mapController = mapView.getController(); mapController.setZoom(13); locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE); locationListener = new GPSLocationListener(); Bundle extras = getIntent().getExtras(); if(extras !=null) { double longitudine = extras.getDouble("long"); double latitudine = extras.getDouble("lat"); ((GPSLocationListener) locationListener).setLongitudine(longitudine); ((GPSLocationListener) locationListener).setLatitudine(latitudine); Log.e("longitudine", "* " + ((GPSLocationListener) locationListener).setLongitudine(longitudine)); Log.e("latitudine", "* " + ((GPSLocationListener) locationListener).setLatitudine(latitudine)); } String provider = null; if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { provider = LocationManager.GPS_PROVIDER; } else if(locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) { provider = LocationManager.NETWORK_PROVIDER; } if(provider != null) { locationManager.requestLocationUpdates(provider, 60000, 15, locationListener); } Criteria crit = new Criteria(); crit.setAccuracy(Criteria.ACCURACY_FINE); best = locationManager.getBestProvider(crit, false); locationManager.requestLocationUpdates(best, 60000, 15, locationListener); Location loc = locationManager.getLastKnownLocation(provider); locationListener.onLocationChanged(loc); } @Override protected boolean isRouteDisplayed() { return false; } @Override protected void onResume() { super.onResume(); //locationManager.requestLocationUpdates(best, 10000, 1, locationListener); Toast.makeText(this, "GPS tracking started", Toast.LENGTH_SHORT).show(); // Start location updates; 5s/5m LocationManager locManager = (LocationManager)getSystemService( Context.LOCATION_SERVICE); locManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 60000, 15, locationListener); Criteria crit = new Criteria(); crit.setAccuracy(Criteria.ACCURACY_FINE); String provider = locManager.getBestProvider(crit, true); Location loc = locManager.getLastKnownLocation(provider); } @Override protected void onPause() { super.onPause(); //locationManager.removeUpdates(locationListener); Toast.makeText(this, "GPS tracking stopped", Toast.LENGTH_SHORT).show(); LocationManager locManager = (LocationManager)getSystemService( Context.LOCATION_SERVICE); locManager.removeUpdates(locationListener); } private class GPSLocationListener implements LocationListener { double longitudine; double latitudine; public double setLongitudine(double longitudine) { return this.longitudine = longitudine; } public double setLatitudine(double latitudine) { return this.latitudine = latitudine ; } public void onLocationChanged(Location location) { Toast.makeText(GPSLocatorActivity.this, "Te plimbi", Toast.LENGTH_SHORT).show(); if (location != null) { Log.e("longitudine", "*2 " + longitudine); Log.e("latitudine", "*2 " + latitudine); GeoPoint pointStatie = new GeoPoint( (int) (latitudine * 1E6), (int) (longitudine * 1E6)); GeoPoint point = new GeoPoint( (int) (location.getLatitude() * 1E6), (int) (location.getLongitude() * 1E6)); // afisaza coordonatele /* Toast.makeText(getBaseContext(), "Latitude: " + location.getLatitude() + " Longitude: " + location.getLongitude(), Toast.LENGTH_SHORT).show(); */ mapController.animateTo(point); mapController.animateTo(pointStatie); mapController.setZoom(13); //mapView.invalidate(); // add marker for people point MapOverlay mapOverlay = new MapOverlay(); mapOverlay.setPointToDraw(point); mapOverlay.setPointToDraw(pointStatie); List&lt;Overlay&gt; listOfOverlays = mapView.getOverlays(); listOfOverlays.clear(); listOfOverlays.add(mapOverlay); String address = ConvertPointToLocation(point); Toast.makeText(getBaseContext(), address, Toast.LENGTH_SHORT).show(); String addressStatie = ConvertPointToLocation(pointStatie); Toast.makeText(getBaseContext(), addressStatie, Toast.LENGTH_SHORT).show(); } } public String ConvertPointToLocation(GeoPoint point) { String address = ""; Geocoder geoCoder = new Geocoder( getBaseContext(), Locale.getDefault()); try { List&lt;Address&gt; addresses = geoCoder.getFromLocation( point.getLatitudeE6() / 1E6, point.getLongitudeE6() / 1E6, 1); if (addresses.size() &gt; 0) { for (int index = 0; index &lt; addresses.get(0).getMaxAddressLineIndex(); index++) address += addresses.get(0).getAddressLine(index) + " "; } } catch (IOException e) { e.printStackTrace(); } return address; } class MapOverlay extends Overlay { private GeoPoint pointToDraw; public void setPointToDraw(GeoPoint point) { pointToDraw = point; } public GeoPoint getPointToDraw() { return pointToDraw; } @Override public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) { super.draw(canvas, mapView, shadow); // convert point to pixels Point screenPts = new Point(); mapView.getProjection().toPixels(pointToDraw, screenPts); // add marker Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.mark_red); canvas.drawBitmap(bmp, screenPts.x, screenPts.y-50, null); return true; } } public void onProviderDisabled(String provider) { } public void onProviderEnabled (String provider) { } public void onStatusChanged(String provider, int status, Bundle extras) { } } } </code></pre>
    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