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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T08:23:58+00:00 2026-06-02T08:23:58+00:00

I have this MapActivity class below showing a map and putting a pin of

  • 0

I have this MapActivity class below showing a map and putting a pin of the user’s current location.
In the other hand I have an Object class VideoLocation which has latitude and longitude of some places which are extracted from a JSON file from the server. I also wanna have the locations are drawn with pins on the map.

How am I able to do that? What do I need to add on my Class below?

FYI this is how I call the object’s latitude and longitude on my ListActivity:

VideoLocation vidLocation = videoLocations[position];

double lat2 = vidLocation.latitude;
double lng2 = vidLocation.longitude; 

This the class:

public class MyMapActivity extends MapActivity implements OnClickListener {
        public static final String TAG = "GoogleMapsActivity";
        private MapView mapView;
        private LocationManager locationManager;
        Geocoder geocoder;
        Location location;
        LocationListener locationListener;
        CountDownTimer locationtimer;
        MapController mapController;
        MapOverlay mapOverlay = new MapOverlay();

        private VideoLocation[] videoLocations = null;

        @Override
        protected void onCreate(Bundle icicle) {
            super.onCreate(icicle);
            setContentView(R.layout.my_map_activity);
            initComponents();

            JsonDB dbhelper = new JsonDB(MyMapActivity.this);
            SQLiteDatabase db = dbhelper.getWritableDatabase();

            db.beginTransaction();
            videoLocations = dbhelper.getVideoLocations(db);
            db.setTransactionSuccessful();//end transaction
            db.endTransaction();
            db.close();

            final ImageButton refresh = (ImageButton) findViewById(R.id.btn_nav_impressum);
            refresh.setOnClickListener(this);

            final ImageButton search =(ImageButton) findViewById(R.id.btn_nav_locater);
            search.setOnClickListener(this);



            locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
            if (locationManager == null) {
                Toast.makeText(MyMapActivity.this,
                        "Location Manager Not Available", Toast.LENGTH_SHORT)
                        .show();
                return;
            }
            location = locationManager
                    .getLastKnownLocation(LocationManager.GPS_PROVIDER);
            if (location == null)
                location = locationManager
                        .getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
            if (location != null) {

                animateMap(location);
                List<Overlay> listOfOverlays = mapView.getOverlays();
                listOfOverlays.clear();
                listOfOverlays.add(mapOverlay);
            }
            locationListener = new LocationListener() {
                @Override
                public void onStatusChanged(String arg0, int arg1, Bundle arg2) {
                }

                @Override
                public void onProviderEnabled(String arg0) {
                }

                @Override
                public void onProviderDisabled(String arg0) {
                }

                @Override
                public void onLocationChanged(Location l) {
                    location = l;
                    locationManager.removeUpdates(this);
                    if (l.getLatitude() == 0 || l.getLongitude() == 0) {
                    } else {
                        double lat = l.getLatitude();
                        double lng = l.getLongitude();
                        showAddress(lat,lng);
                    }
                }
            };
            if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER))
                locationManager.requestLocationUpdates(
                        LocationManager.GPS_PROVIDER, 1000, 10f, locationListener);
            locationManager.requestLocationUpdates(
                    LocationManager.NETWORK_PROVIDER, 1000, 10f, locationListener);
            locationtimer = new CountDownTimer(30000, 5000) {
                @Override
                public void onTick(long millisUntilFinished) {
                    if (location != null)
                        locationtimer.cancel();
                }

                @Override
                public void onFinish() {
                    if (location == null) {
                    }
                }
            };
            locationtimer.start();
        }

        public void animateMap(Location location){
        double lat = location.getLatitude();
            double lng = location.getLongitude();

            GeoPoint point = new GeoPoint((int) (lat * 1E6), (int) (lng * 1E6));
            GeoPoint point2 = new GeoPoint((int) (lat2 * 1E6), (int) (lng2 * 1E6));
            mapController.animateTo(point, new Message());
            mapOverlay.setPointToDraw(point);

        }


        public MapView getMapView() {
            return this.mapView;
        }

        private void initComponents() {
            mapView = (MapView) findViewById(R.id.mapView);
            mapView.setBuiltInZoomControls(true);
            mapController = mapView.getController();
            mapController.setZoom(16);
        }

        @Override
        protected boolean isRouteDisplayed() {
            return false;
        }

        class MapOverlay extends Overlay {
            private GeoPoint pointToDraw;

            public void setPointToDraw(GeoPoint point) {
                pointToDraw = point;
            }

            public GeoPoint getPointToDraw() {
                return pointToDraw;
            }

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

                Point screenPts = new Point();
                mapView.getProjection().toPixels(pointToDraw, screenPts);

                Bitmap bmp = BitmapFactory.decodeResource(getResources(),
                        R.drawable.pin_normal);
                canvas.drawBitmap(bmp, screenPts.x, screenPts.y - 24, null);
                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-02T08:24:00+00:00Added an answer on June 2, 2026 at 8:24 am

    adding ItemizedOverlay class would be better if you want to add pin (or images) on top of your map.
    package com.android.testandroidmap;

    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 HelloItemizedOverlay extends ItemizedOverlay {
    
    private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
    private Context mContext;
    
    public HelloItemizedOverlay(Drawable defaultMarker, Context context) {
        super(boundCenterBottom(defaultMarker));
        // TODO Auto-generated constructor stub
        mContext = context;
    }
    
    @Override
    protected OverlayItem createItem(int i) {
        // TODO Auto-generated method stub
        return mOverlays.get(i);
    }
    
    @Override
    public int size() {
        // TODO Auto-generated method stub
        return mOverlays.size();
    }
    
    public void addOverlay(OverlayItem overlay) {
        mOverlays.add(overlay);
        populate();
    }
    
    @Override
    protected boolean onTap(int index) {
      OverlayItem item = mOverlays.get(index);
      AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
      dialog.setTitle(item.getTitle());
      dialog.setMessage(item.getSnippet());
      dialog.show();
      return true;
    }
    }
    

    I get this code from Android Developer Official Guide, and with this class on your code, you can add the overlays.

    Add all the things you need (container, image for pins, and the pin+coordinate overlay)

    List<Overlay> mapOverlays = mapView.getOverlays();
    Drawable drawable = this.getResources().getDrawable(R.drawable.androidmarker);
    HelloItemizedOverlay itemizedoverlay = new HelloItemizedOverlay(drawable, this);
    

    for your icons to be recognized by the class before, and also instantiate the coordinate, add the coordinate to an overlayItem + register the overlayItem with the HelloItemizedOverlay you made before

    GeoPoint point = new GeoPoint(19240000,-99120000);
    OverlayItem overlayitem = new OverlayItem(point, "Hola, Mundo!", "I'm in Mexico City!");
    itemizedoverlay.addOverlay(overlayitem);
    

    finish with adding the overlay to the mapOverlay, which is a collection of overlays.

    mapOverlays.add(itemizedoverlay);
    

    This displays a pin on top of my map, which can be customized by any image you want. If you want to also use different images for each location, just instantiate another Drawable with your image and register that Drawable to other HelloItemizedOverlay.

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

Sidebar

Related Questions

I have written one MapActivity class that is able to display a set of
I have added multiple ovals on map view by using below code but I
I have this situation where i have to start an activity from my mainActivity.
Have this query: SELECT HOUR( DATE ) AS hr, COUNT( * ) AS cnt
Have this self-made slider: http://jsfiddle.net/wyc3P/4/ What it does: takes min and max values in
I have this kind of mysql db (table name/fields) tbl_users : id, title, approved
I have this heregex in coffeescript trying to catch urls: regex = /// (
I have this bxslider code. $(function(){ $('#slider1').bxSlider({ infiniteLoop: false, hideControlOnEnd: true }); }); and
I have this this View for rendering form @using ExpertApplication.ViewModels @model IEnumerable<QuestionViewModel> @{ ViewBag.Title
i have this regular expression: <%(?<begintag>[^>]+)%>(?<inner>(.+?))<%/(?<endtag>[^%]+)%> what i want to achive is, check for

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.