Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here is the code </p> <p>Main MapActivity</p> <pre><code> public class WhereIam extends MapActivity { MapController mapController; MyPositionOverlay positionOverlay; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); MapView myMapView=(MapView)findViewById(R.id.myMapView); myMapView.setSatellite(true); myMapView.setBuiltInZoomControls(true); mapController=myMapView.getController(); mapController.setZoom(17); positionOverlay = new MyPositionOverlay(); List&lt;Overlay&gt; overlays = myMapView.getOverlays(); overlays.add(positionOverlay); LocationManager locationManager; String context=Context.LOCATION_SERVICE; locationManager=(LocationManager)getSystemService(context); Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); criteria.setAltitudeRequired(false); criteria.setBearingRequired(false); criteria.setCostAllowed(true); criteria.setPowerRequirement(Criteria.POWER_LOW); String provider = locationManager.getBestProvider(criteria, true); Location location = locationManager.getLastKnownLocation(provider); final LocationListener locationListener = new LocationListener() { public void onLocationChanged(Location location) { updateWithNewLocation(location); } public void onProviderDisabled(String provider){ updateWithNewLocation(null); } public void onProviderEnabled(String provider){ } public void onStatusChanged(String provider, int status, Bundle extras){ } }; updateWithNewLocation(location); locationManager.requestLocationUpdates(provider, 2000, 10, locationListener); } private void updateWithNewLocation(Location location) { if(location!=null) { // Update the map location. positionOverlay.setLocation(location); Double geoLat = location.getLatitude()*1E6; Double geoLng = location.getLongitude()*1E6; GeoPoint point = new GeoPoint(geoLat.intValue(), geoLng.intValue()); mapController.animateTo(point); } } @Override protected boolean isRouteDisplayed() { return true; } </code></pre> <p>Another MyPositionOverlay class </p> <pre><code>public class MyPositionOverlay extends Overlay { Location location; private final int mRadius = 5; @Override public void draw(Canvas canvas, MapView mapView, boolean shadow) { Projection projection = mapView.getProjection(); if (shadow == false) { // Get the current location Double latitude = location.getLatitude()*1E6; Double longitude = location.getLongitude()*1E6; GeoPoint geoPoint; geoPoint = new GeoPoint(latitude.intValue(),longitude.intValue()); // Convert the location to screen pixels Point point = new Point(); projection.toPixels(geoPoint, point); RectF oval = new RectF(point.x - mRadius, point.y - mRadius, point.x + mRadius, point.y + mRadius); // Setup the paint Paint paint = new Paint(); paint.setARGB(250, 255, 0, 0); paint.setAntiAlias(true); paint.setFakeBoldText(true); Paint backPaint = new Paint(); backPaint.setARGB(175, 50, 50, 50); backPaint.setAntiAlias(true); RectF backRect = new RectF(point.x + 2 + mRadius, point.y - 3*mRadius, point.x + 65, point.y + mRadius); // Draw the marker canvas.drawOval(oval, paint); canvas.drawRoundRect(backRect, 5, 5, backPaint); canvas.drawText("Here I Am", point.x + 2*mRadius, point.y, paint); } super.draw(canvas, mapView, shadow); } @Override public boolean onTap(GeoPoint point, MapView mapView) { return false; } public Location getLocation() { return location; } public void setLocation(Location location) { this.location = location; } } </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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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