Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8547165
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T13:12:27+00:00 2026-06-11T13:12:27+00:00

I am following this tutorial enter link description here . The Problem is that

  • 0

I am following this tutorial enter link description here. The Problem is that mapView.setBuiltInZoomControls(true) doesn’t work at all…but when I use mapView.setClickable(true) then it works. BUt then my onTouch.. method doesn’t fires up. Here is the complete code.

package com.emazdoor.gpsmap;

import java.util.List;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Point;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.widget.Toast;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;

public class GPSMap_Activity extends MapActivity {

    private LocationManager locationManager;
    public MyLocationListener locationListener;
    private MapView mapView;
    private MapController mapcontroller;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_gpsmap_);
        mapView = (MapView) findViewById(R.id.mapview);
        mapcontroller = mapView.getController();
        mapView.setBuiltInZoomControls(true);
//      mapView.setClickable(true);


        String coordinates[] = { "30", "71" };
        double latitude = Double.parseDouble(coordinates[0]);
        double longitude = Double.parseDouble(coordinates[1]);

        GeoPoint p = new GeoPoint((int) (latitude * 1E6),
                (int) (longitude * 1E6));

        mapcontroller.animateTo(p);
        mapcontroller.setZoom(7);
        mapView.invalidate();

        locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        locationListener = new MyLocationListener();
        locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0,
                0, locationListener);

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
        case R.id.my_location:
            Toast.makeText(GPSMap_Activity.this, "Moving to current Location",
                    Toast.LENGTH_LONG).show();
            locationListener.gpsCurrentLocation();
            return true;
        case R.id.mapview_setellite:
            Toast.makeText(GPSMap_Activity.this, "Satellite View",
                    Toast.LENGTH_LONG).show();
            if (mapView.isSatellite() == false)
                mapView.setSatellite(true);
            return true;
        case R.id.mapview_normal:
            Toast.makeText(GPSMap_Activity.this, "Normal View",
                    Toast.LENGTH_LONG).show();
            if (mapView.isSatellite() == true)
                mapView.setSatellite(false);
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    @Override
    protected boolean isRouteDisplayed() {

        return false;
    }


    @Override
    public boolean onTouchEvent(MotionEvent event) {
        if (event.getAction() == 1) {
            GeoPoint p = mapView.getProjection().fromPixels((int) event.getX(),
                    (int) event.getY());
            Toast.makeText(GPSMap_Activity.this,
                    p.getLatitudeE6() / 1E6 + " " + p.getLongitudeE6() / 1E6,
                    Toast.LENGTH_LONG).show();
        }
        return true;
    }

    public class MyLocationListener implements LocationListener {

        private double tempLatitude, tempLongitude;


        public void onLocationChanged(Location location) {
            location.getLatitude();
            location.getLatitude();
            String text = "My current Location is:" + " Latitude= "
                    + location.getLatitude() + " Longitude= "
                    + location.getLongitude();

            Toast.makeText(GPSMap_Activity.this, text, Toast.LENGTH_LONG)
                    .show();

            if (location.getLatitude() == 71) {
                AlertDialog.Builder alertBox = new AlertDialog.Builder(
                        GPSMap_Activity.this);
                alertBox.setMessage("You have Entered in wrong place");
                alertBox.setNeutralButton("OK",
                        new DialogInterface.OnClickListener() {


                            public void onClick(DialogInterface dialog,
                                    int which) {
                            }
                        });
                alertBox.show();
            }

            tempLatitude = location.getLatitude();
            tempLongitude = location.getLongitude();

            this.gpsCurrentLocation();
        }

        public void gpsCurrentLocation() {
            String coordinates[] = { "" + tempLatitude, "" + tempLongitude };
            double latitude = Double.parseDouble(coordinates[0]);
            double longitude = Double.parseDouble(coordinates[1]);

            GeoPoint p = new GeoPoint((int) (latitude * 1E6),
                    (int) (longitude * 1E6));

            mapcontroller.animateTo(p);
            mapcontroller.setZoom(7);

            MyMapOverlay marker = new MyMapOverlay(p);
            List<Overlay> listofover = mapView.getOverlays();
            listofover.clear();
            listofover.add(marker);

            mapView.invalidate();

        }

        public void onProviderDisabled(String provider) {
            // TODO Auto-generated method stub

        }

        public void onProviderEnabled(String provider) {
            // TODO Auto-generated method stub

        }

        public void onStatusChanged(String provider, int status, Bundle extras) {
            // TODO Auto-generated method stub

        }


    }

    public class MyMapOverlay extends Overlay {

        GeoPoint locationGeo = null;

        public MyMapOverlay(GeoPoint location) {
            this.locationGeo = location;
        }

        @Override
        public void draw(Canvas canvas, MapView mapView, boolean shadow) {
            super.draw(canvas, mapView, shadow);

            Point screenPoint = new Point();
            mapView.getProjection().toPixels(this.locationGeo, screenPoint);

            canvas.drawBitmap(BitmapFactory.decodeResource(getResources(),
                    R.drawable.ic_delete), screenPoint.x, screenPoint.y, null);
        }

    }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T13:12:29+00:00Added an answer on June 11, 2026 at 1:12 pm
    Use Touch Event in MapOverlay class.
    
    
     public class MyMapOverlay extends com.google.android.maps.Overlay
    { 
    
    
                GeoPoint locationGeo = null; 
    
    
                public MyMapOverlay(GeoPoint location)
                { 
                    this.locationGeo = location; 
                } 
    
    
    
                @Override 
                public void draw(Canvas canvas, MapView mapView, boolean shadow) { 
                    super.draw(canvas, mapView, shadow); 
    
                    Point screenPoint = new Point(); 
                    mapView.getProjection().toPixels(this.locationGeo, screenPoint); 
    
                    canvas.drawBitmap(BitmapFactory.decodeResource(getResources(), 
                            R.drawable.ic_delete), screenPoint.x, screenPoint.y, null); 
                } 
    
    
    
         @Override 
            public boolean onTouchEvent(MotionEvent event) { 
                if (event.getAction() == 1) { 
                    GeoPoint p = mapView.getProjection().fromPixels((int) event.getX(), 
                            (int) event.getY()); 
                    Toast.makeText(GPSMap_Activity.this, 
                            p.getLatitudeE6() / 1E6 + " " + p.getLongitudeE6() / 1E6, 
                            Toast.LENGTH_LONG).show(); 
                } 
                return true; 
            } 
    
    
    
            } 
    
    
    In Xml:
    
    
    <com.google.android.maps.MapView
            android:id="@+id/mapView"
            android:layout_width="fill_parent"
            android:layout_height="250dip"
            android:layout_alignParentLeft="true"
            android:apiKey="@string/Google_Api_key"
            android:clickable="true" >
    
        </com.google.android.maps.MapView>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i'm following this tutorial: http://code.google.com/p/modwsgi/wiki/QuickInstallationGuide and downloading my own source of mod_wsgi. The problem
I was following this tutorial: http://www.vogella.com/articles/AndroidLocationAPI/article.html --> Paragraph 6.0 Problem: My emulator runs perfectly
I'm following this tutorial on building a widget IN that tutorial, he's testing whether
I'm doing this simple tutorial on the following website: http://www.phpeasystep.com/phptu/6.html Is the code that
Following this tutorial and running into trouble. [TestMethod] [ExpectedException(typeof(Exception))] public void VerifyPropertyNameMethod_NonExistentPropertyString_ThrowsException() { var
Following this tutorial (http://www.asp.net/mvc/tutorials/getting-started-with-ef-using-mvc/handling-concurrency-with-the-entity-framework-in-an-asp-net-mvc-application), I learned how to save data and do concurrency checks
I was following this tutorial , but for the life of me I cant
I'm following this tutorial for twitter4j: http://www.javacodegeeks.com/2011/10/java-twitter-client-with-twitter4j.html and I've gotten almost everything right. All
I'm following this tutorial: http://developer.android.com/training/basics/firstapp/running-app.html#Emulator In it there is a simple code for a
I am following this tutorial http://ebiquity.umbc.edu/Tutorials/Hadoop/14%20-%20start%20up%20the%20cluster.html They are using hadoop version hadoop-0.19.1. The version

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.