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 6578101
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:43:39+00:00 2026-05-25T15:43:39+00:00

i am trying to put a new marker everytime the user touches the screen.

  • 0

i am trying to put a new marker everytime the user touches the screen.
the following is my code, my problem is that the new marker doesn’t appear at all

package com.org;

import java.io.IOException;
import java.util.List;
import java.util.Locale;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Point;
import android.location.Address;
import android.location.Geocoder;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.widget.LinearLayout;
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.MyLocationOverlay;
import com.google.android.maps.MapView.LayoutParams;
import com.google.android.maps.Overlay;

public class MapExampleActivity extends MapActivity {
MapView mapView;
MapController mc;
GeoPoint p;
MapOverlay mapOverlay = new MapOverlay();
private MyLocationOverlay myLocOverlay;

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.marker);
        canvas.drawBitmap(bmp, screenPts.x + 25, screenPts.y - 50,null);
        return true;
    }
}


@SuppressWarnings("deprecation")
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);


            mapView = (MapView) findViewById(R.id.mymap);
     LinearLayout zoomLayout = (LinearLayout)findViewById  (R.id.myzoom);  
            View zoomView = mapView.getZoomControls(); 

            zoomLayout.addView(zoomView, 
                new LinearLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, 
                    LayoutParams.WRAP_CONTENT)); 
            mapView.displayZoomControls(true);

            mc = mapView.getController();
            String coordinates[] = {"1.352566007", "103.78921587"};
            double lat = Double.parseDouble(coordinates[0]);
            double lng = Double.parseDouble(coordinates[1]);

            p = new GeoPoint(
                (int) (lat * 1E6), 
                (int) (lng * 1E6));

            mc.animateTo(p);
            mc.setZoom(17); 


    // ---Add a location marker---
    MapOverlay mapOverlay = new MapOverlay();
    List<Overlay> listOfOverlays = mapView.getOverlays();
    listOfOverlays.clear();
    listOfOverlays.add(mapOverlay);

    mapView.invalidate();

}


@Override
protected boolean isRouteDisplayed() {
    // TODO Auto-generated method stub
    return false;
}
public boolean onTouchEvent(MotionEvent event, MapView mapView) 
     {   
     //---when user lifts his finger---
     if (event.getAction() == 1) {                
          GeoPoint p1 = mapView.getProjection().fromPixels(
             (int) event.getX(),
             (int) event.getY());


                 mc.animateTo(p1);
                 mc.setCenter(p1);
                 return true;
     }                            
     else 
         return false;
  }        


  }
  • 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-05-25T15:43:40+00:00Added an answer on May 25, 2026 at 3:43 pm

    Try this one. Replace your overlay onDraw() method with this one:

    @Override
    public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) {
    super.draw(canvas, mapView, shadow);    
    Point screenPts = new Point();
    mapView.getProjection().toPixels(p, screenPts);
    for(int i=0;i<markerList.size();i++) {
        canvas.drawBitmapbmp(markerList.get(i), screenPts.x + 25, screenPts.y - 50,null);
    }
       return false;
    }
    

    and add this method to your overlay class and also create a markerList at the top of your overlay class.

    public boolean onTap(GeoPoint p, MapView map) {
    
    Point screenPts = new Point();
    mapView.getProjection().toPixels(p, screenPts);
    
    // ---add the marker---
    Bitmap bmp = BitmapFactory.decodeResource(getResources(),R.drawable.marker);
    markerList.add(bmp);
    return true;            
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to put together a new app for a project that will display
What's up y'all, I am trying to write some code in Java that will
I'm trying to put a new customized widget when the user press a button,
On this page: http://www.palosverdes.com/sandbox/9slategrey/index.cfm I'm trying to put in a new menu (the one
I'm trying to put some specs around a new rails 3 project I am
I'm trying to put in a Toast the selected value from ListView . listView1.setOnItemClickListener(new
Trying to put a regex expression together that returns the string between _ and
I trying to put together an Android app that will take a picture and
I am trying to put the marker on the map and i have done
I am trying to change the marker icon and put my own icon with

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.