Note that there are some explanatory texts on larger screens.

plurals
  1. POOverlay not drawing on the right spot
    primarykey
    data
    text
    <p>I have an extremely weird issue.</p> <p>First of all, when I zoom in and out of a MapView, the marker (overlay) moves to incorrect places (doesn't work well with scaling).</p> <p>Secondly, the market is being drawn at the wrong position!</p> <p>I'll post code below but first listen to this:</p> <p>I'm in Islamabad. The GeoCoder also tells me I'm in Islamabad. But when I draw a circle around my location using overlays, it draws it in a city that's 100s of kilometers away.</p> <p>Kindly help me with both the problems.</p> <p>Here's the activity:</p> <pre><code>public class LocatePickup extends MapActivity implements LocationListener { Geocoder gc; MapView mapView; MapController mc; GeoPoint p; double lat = 0; double lng = 0; LocationManager lm; WebMethods wm; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.locate_pickup); mapView = (MapView) findViewById(R.id.mapView); mapView.setBuiltInZoomControls(true); mapView.setStreetView(true); lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE); lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 1000L, 500.0f, this); Location l = new Location(LocationManager.NETWORK_PROVIDER); l = lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); mc = mapView.getController(); p = new GeoPoint((int) (l.getLatitude()), (int) (l.getLongitude())); mc.setCenter(p); mc.setZoom(14); MapOverlay myLocationOverlay = new MapOverlay(); List&lt;Overlay&gt; list = mapView.getOverlays(); list.add(myLocationOverlay); gc = new Geocoder(this); try { List&lt;Address&gt; address = gc.getFromLocation(l.getLatitude(), l.getLongitude(), 1); Toast.makeText(this, ""+address.get(0).getAddressLine(1), 1).show(); } catch (IOException e) { e.printStackTrace(); } } @Override protected boolean isRouteDisplayed() { return false; } class MapOverlay extends com.google.android.maps.Overlay { Paint paint = new Paint(); @Override public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) { super.draw(canvas, mapView, shadow); Point myScreenCoords = new Point(); mapView.getProjection().toPixels(p, myScreenCoords); paint.setStrokeWidth(1); paint.setARGB(255, 218, 28, 28); paint.setStyle(Paint.Style.STROKE); //Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.pin); canvas.drawCircle(myScreenCoords.x, myScreenCoords.y, 15, paint); //(bmp, myScreenCoords.x, myScreenCoords.y - 256, paint); canvas.drawText("Hey!", myScreenCoords.x, myScreenCoords.y, paint); return true; } } @Override public void onLocationChanged(Location arg0) { if(arg0 != null) { Log.d("New Location: ", arg0.getLatitude() + " - " + arg0.getLongitude()); lat = arg0.getLatitude(); lng = arg0.getLongitude(); p = new GeoPoint((int) lat * 1000000, (int) lng * 1000000); mc.animateTo(p); } } @Override public void onProviderDisabled(String provider) { // empty } @Override public void onProviderEnabled(String provider) { // empty } @Override public void onStatusChanged(String provider, int status, Bundle extras) { //empty } } </code></pre> <p>Once the code is complete, I'd like the user to be able to tap a spot on the map and get its address (the marker should move to that spot as well). But it should be accurate.</p>
    singulars
    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.
 

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