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

  • Home
  • SEARCH
  • 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 8882559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:36:35+00:00 2026-06-14T20:36:35+00:00

I have been using a previous question and a Google Tutorial to attempt to

  • 0

I have been using a previous question and a Google Tutorial to attempt to add multiple pin images on a Google Map view when the current location of the user changes.

Each pin when tapped displays the Longitude and Latitude of the pin.

However currently my code only displays one pin and does not add another image when the location of the user changes. I am relatively new to Android and can’t see why this code wouldn’t work?

Map.java:

import java.util.List;

import android.graphics.drawable.Drawable;
import android.os.Bundle;

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;
import com.google.android.maps.MyLocationOverlay;
import com.google.android.maps.OverlayItem;

import android.util.Log;


public class Map extends MapActivity {
   private MapView map;
   private MapController controller;
   private double lon, lat;
   private Drawable drawable;
   private MapOverlay itemizedoverlay;
   private List<Overlay> mapOverlays;

   @Override
   public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);

      setContentView(R.layout.maps);
      initMapView();
      mapOverlays = map.getOverlays();
      drawable = this.getResources().getDrawable(R.drawable.pin);
      itemizedoverlay = new MapOverlay(drawable, this);
      initMyLocation();

   }





   private void initMapView() {
      map = (MapView) findViewById(R.id.map);
      controller = map.getController();
      map.setSatellite(true);
      map.setBuiltInZoomControls(true);
   }


   private void initMyLocation() {
      final MyLocationOverlay overlay = new MyLocationOverlay(this, map);
      overlay.enableMyLocation();
      overlay.enableCompass(); // wont work in emulator
      overlay.runOnFirstFix(new Runnable() {
         public void run() {
            // Zoom in to current location - 1 is word view
            controller.setZoom(20);
            controller.animateTo(overlay.getMyLocation());
            lon = overlay.getMyLocation().getLongitudeE6();

            lat = overlay.getMyLocation().getLatitudeE6();
            setLON(lon);
            setLAT(lat);
            //-0.959896
            //51.742953
            Log.w("test-lon", Double.toString(lon/1E6));
            Log.w("test-lat", Double.toString(lat/1E6));
            GeoPoint point = new GeoPoint((int)(lat),(int)(lon));

            mapOverlays.add(itemizedoverlay);
            test(point);
         }
      });





      map.getOverlays().add(overlay);

   }

   public void setLON(double x){ //remove?

       lon = x;

   }
 public void setLAT(double x){ //remove?

       lat = x;
   }
   public void test(GeoPoint px){

       OverlayItem overlayitem = new OverlayItem(px,"Test Point" , "Lat: " + Double.toString(lat/1E6) + "\nLon: " + Double.toString(lon/1E6) );
       itemizedoverlay.addOverlay(overlayitem);


   }


   @Override
   protected boolean isRouteDisplayed() {
      // Required method from MapActivity


      return false;
   }
}

MapOverlay.java:

import java.util.ArrayList;

import android.app.AlertDialog;
import android.content.Context;
import android.graphics.drawable.Drawable;

import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.OverlayItem;

public class MapOverlay extends ItemizedOverlay {

    private ArrayList<OverlayItem> mapOverlay = new ArrayList<OverlayItem>();
    private Context mContext;

    public MapOverlay (Drawable defaultMarker, Context context) {
          super(boundCenterBottom(defaultMarker));
          mContext = context;
        }

    public MapOverlay(Drawable arg0) {
        super(boundCenterBottom(arg0));

    }


    public void addOverlay(OverlayItem overlay) {
        mapOverlay.add(overlay);
        populate();
    }

    @Override
    protected OverlayItem createItem(int i) {
      return mapOverlay.get(i);
    }

    @Override
    public int size() {
        return mapOverlay.size();
    }


    @Override
    protected boolean onTap(int index) {
      OverlayItem item = mapOverlay.get(index);
      AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
      dialog.setTitle(item.getTitle());
      dialog.setMessage(item.getSnippet());
      dialog.show();
      return true;
    }

}
  • 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-14T20:36:36+00:00Added an answer on June 14, 2026 at 8:36 pm

    u need implements class LocationListener for listen our location changes and update on the map.

    class LocationsListeners implements LocationListener {
    
        @Override
        public void onLocationChanged(Location location) {
            setLAT(location.getLatitude());
            setLON(location.getLongitude());
            setGeoPoint(lat, lon);
            mapOverlays.add(geoPoint);          
        }
    
        @Override
        public void onProviderDisabled(String provider) {
            // TODO Auto-generated method stub
    
        }
    
        @Override
        public void onProviderEnabled(String provider) {
            // TODO Auto-generated method stub
    
        }
    
        @Override
        public void onStatusChanged(String provider, int status, Bundle extras) {
            // TODO Auto-generated method stub
    
        }
    
    }
    

    u need method for calc the GeoPoint:

        public GeoPoint setGeoPoint(double lat, double lon){
           geoPoint = new GeoPoint((int) (lat * 1E6), (int)(lon  * 1E6));
           return geoPoint;
        }
    

    or using Little Fluffy Location – Its library that updates our location and notify u, is broadcast receiver, very simple and fast implementation:

    try:

    http://code.google.com/p/little-fluffy-location-library/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So using the advice found in my previous ' question ', I have been
NOTE: This is the simple version of my previous question that SHOULD have been
This leads on from my previous question here . I have been developing with
A lot of answers to my previous question have been suggestions that i stop
I have been using TortoiseSVN for some time and I really like it. I
I have been using Stanford POS Tagger to tag parts of speech in a
I have been using play 1.2.5rc4 for development of one app and I have
I have been using an API to do some work. This is how I
I have been using some Javascript to create a text field once an certain
I have been using the storyboard to make an application and currently there are

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.