Help regarding map view and overlay.


Last Updated:

  1. shreya_wip

    shreya_wip New Member

    Need small help regarding map view and overlay.

    i have map activity and also showing markers using ItemizedOverlay.
    My problem is i want static image for mapView i.e my map should not be zoomed and i should not be able to drag it also. But when i tapped on marker it should display some toast or dialog.

    below is sample of my code
    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    RelativeLayout rv = (RelativeLayout) findViewById(R.id.relative);

    LinearLayout ll = new LinearLayout(this);
    ll.setOrientation(LinearLayout.VERTICAL);
    rv.addView(ll);
    int lenght = addressAndPhoneNos.length;

    for (int i = 0; i < lenght; i++) {
    TextView header = new TextView(this);
    TextView blank = new TextView(this);
    phoneNo = new TextView(this);
    TextView addr = new TextView(this);

    header.setText(addressAndPhoneNos[0]);
    ll.addView(header);

    addr.setText(addressAndPhoneNos[1]);
    ll.addView(addr);

    phoneNo.setText("Operator: " + addressAndPhoneNos[2]);
    phoneNo.setClickable(true);
    Linkify.addLinks(phoneNo, Linkify.ALL);
    ll.addView(phoneNo);

    blank.setText("");
    ll.addView(blank);

    }

    Button direction=(Button)findViewById(R.id.direction);
    direction.setOnClickListener(new View.OnClickListener() {

    private Uri uri;

    public void onClick(View v) {
    double latitude = 12.306080;
    double longitude = 76.656432;
    uri = Uri.parse("geo:" + latitude + "," + longitude +"?z=10");
    Intent intent = new Intent(Intent.ACTION_VIEW, uri);
    startActivity(intent);
    // Intent myIntent = new Intent(MainActivity.this, LaunchMapActivity.class);
    //MainActivity.this.startActivity(myIntent);

    }// end of onClick

    }

    );// end of setOnClickListener


    mapView = (MapView) findViewById(R.id.mapView);
    mapView.setFocusable(false) ;
    mapView.setBuiltInZoomControls(false);


    /* mapView.setOnTouchListener(new View.OnTouchListener() {

    @Override
    public boolean onTouch(View arg0, MotionEvent arg1) {
    //Toast.makeText(getApplicationContext(), "mapView touch", Toast.LENGTH_SHORT)
    // .show();
    if (arg1.getAction() == 1) {

    mapView.setClickable(false);
    return true;
    }
    else
    {
    mapView.setClickable(true);
    return true;
    }

    }
    });*/



    List<Overlay> mapOverlays = mapView.getOverlays();
    Drawable drawable = this.getResources().getDrawable(
    R.drawable.marker);

    MapItemizedOverlay itemizedoverlay = new MapItemizedOverlay(drawable,
    this);
    mapController = mapView.getController();


    int minLat = Integer.MAX_VALUE;
    int maxLat = Integer.MIN_VALUE;
    int minLon = Integer.MAX_VALUE;
    int maxLon = Integer.MIN_VALUE;


    List<GeoPoint> geoPoints = new ArrayList<GeoPoint>();

    int geoPoints_length = latitudeLongitude.length;

    for (int i = 0; i < geoPoints_length; i++) {
    GeoPoint point = new GeoPoint((int) (latitudeLongitude[0]* 1E6), (int) (latitudeLongitude[1] * 1E6));
    geoPoints.add(point);

    OverlayItem overlayitem = new OverlayItem(point,
    "Title for dialog", pinAddress);
    itemizedoverlay.addOverlay(overlayitem);
    }

    for (GeoPoint item :geoPoints)
    {

    int lat = item.getLatitudeE6();
    int lon = item.getLongitudeE6();

    maxLat = Math.max(lat, maxLat);
    minLat = Math.min(lat, minLat);
    maxLon = Math.max(lon, maxLon);
    minLon = Math.min(lon, minLon);
    }

    double fitFactor = 1.5;
    mapController.zoomToSpan((int) (Math.abs(maxLat - minLat) * fitFactor),
    (int)(Math.abs(maxLon - minLon) * fitFactor));
    mapController.animateTo(new GeoPoint( (maxLat + minLat)/2,
    (maxLon + minLon)/2 ));

    mapOverlays.add(itemizedoverlay);


    --------------------------------------------
    in
    public class MapItemizedOverlay extends ItemizedOverlay<OverlayItem>{
    public boolean onTap (final GeoPoint p, final MapView mapView){


    if (super.onTap(p, mapView)) {

    return true;
    }
    else
    {
    //mapView.setClickable(false);
    return false;

    }

    }
    }

    Advertisement
  2. Digital Controller

    Digital Controller The Real Bass Creator Guide

    Welcome to the forums :)

    I am going to move your thread to Application Development as that's what it looks like you are dealing with here, so hope this is alright and thanks for joining :D
  3. Rush

    Rush {<>}~{<>} Guide

    Hello and welcome aboard... shreya.

    Unfortunately, I won't be able to assist you with your concerns, however, hopefully someone with this type knowledge will chime in to assist you.

Share This Page