Note that there are some explanatory texts on larger screens.

plurals
  1. POGeo Coding error
    primarykey
    data
    text
    <p>I am trying to update location name of every location user touches on screen i.e when user lifts finger up code traces the lat and longs by pixels and fires a geocoding request My code for the activity is</p> <pre><code>package scheduler.scheduler; import java.util.List; import com.google.android.maps.MapView.LayoutParams; import android.view.View; import android.widget.LinearLayout; import android.app.Activity; import android.os.Bundle; import com.google.android.maps.MapActivity; import com.google.android.maps.MapView; import com.google.android.maps.GeoPoint; import com.google.android.maps.MapController; import com.google.android.maps.Overlay; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Canvas; import android.graphics.Point; import android.os.Bundle; import android.view.View; import android.widget.LinearLayout; import java.io.IOException; import android.view.MotionEvent; import android.location.Geocoder; import java.util.Locale; import android.widget.Toast; import android.location.Address; public class mapz extends MapActivity { /** Called when the activity is first created. */ MapView mapView; MapController mc; GeoPoint p; 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.pushpin); //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(), "hii", Toast.LENGTH_SHORT).show(); } catch (IOException e) { e.printStackTrace(); } return true; } else return false; } } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.maplayout); mapView = (MapView) findViewById(R.id.mapView); LinearLayout zoomLayout = (LinearLayout)findViewById(R.id.zoom); View zoomView = mapView.getZoomControls(); zoomLayout.addView(zoomView, new LinearLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); mapView.displayZoomControls(true); mc = mapView.getController(); String coordinates[] = {"18.116667", "83.416667"}; double lat = Double.parseDouble(coordinates[0]); double lng = Double.parseDouble(coordinates[1]); p = new GeoPoint( (int) (lat * 1E6), (int) (lng * 1E6)); mc.animateTo(p); //---Add a location marker--- MapOverlay mapOverlay = new MapOverlay(); List&lt;Overlay&gt; listOfOverlays = mapView.getOverlays(); listOfOverlays.clear(); listOfOverlays.add(mapOverlay); mapView.invalidate(); } @Override protected boolean isRouteDisplayed() { return false; } } </code></pre> <p>Activity is loading and Map is loading but when i click and release mouse the intended action i.e "The address of location shall be displayed" is not working when i check LOGCAT it shows </p> <p><img src="https://i.stack.imgur.com/LjzUj.png" alt="enter image description here"></p> <p>Any expert please try to help me i have to fix it fast its my project work!</p>
    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.
 

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