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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T19:14:44+00:00 2026-06-06T19:14:44+00:00

try { JSONArray jArray = new JSONArray(result); for(int i=0;i<jArray.length();i++) { JSONObject json_data = jArray.getJSONObject(i);

  • 0
    try
    {
            JSONArray jArray = new JSONArray(result);
            for(int i=0;i<jArray.length();i++)
            {
                    JSONObject json_data = jArray.getJSONObject(i);                       
                    //Retrieve data from db. lat & long = double / name = String
                    latMarker = json_data.getDouble("latitude");
                    lonMarker = json_data.getDouble("longitude");
                    nameMarker = json_data.getString("name");
                    List<Overlay> mapOverlays = mapView.getOverlays();
                    Drawable drawable = this.getResources().getDrawable(R.drawable.ic_launcher);
                    CustomItemizedOverlay itemizedOverlay = 
                         new CustomItemizedOverlay(drawable, this);

                    markers = new GeoPoint (
                            (int) (latMarker * 1E6),
                            (int) (lonMarker * 1E6));

                    //Happens when a marker is clicked
                    OverlayItem overlayitem = new OverlayItem(markers, "Tapped", "Name: " + nameMarker);
                    itemizedOverlay.addOverlay(overlayitem);
                    mapOverlays.add(itemizedOverlay);           
            }
    }
    catch(JSONException e)
    {
            Log.e("log_tag", "Error parsing data. " + e.toString());
    }        
}

I made an android application and integrated Google Maps to it. I also added markers on places that are located around my city. And my problem is, I dont know how to add text above these markers. Can anyone help me, please?

  • 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-06T19:14:45+00:00Added an answer on June 6, 2026 at 7:14 pm
    package com.labs;
    
    import java.util.ArrayList;
    
    import android.graphics.Paint;
    import android.graphics.Point;
    import android.graphics.Rect;
    import android.graphics.RectF;
    import android.graphics.drawable.BitmapDrawable;
    import android.graphics.drawable.Drawable;
    import android.text.TextPaint;
    
    import com.google.android.maps.GeoPoint;
    import com.google.android.maps.ItemizedOverlay;
    import com.google.android.maps.MapView;
    import com.google.android.maps.OverlayItem;
    
    public class ResoucesOverlay extends ItemizedOverlay
    {
    
        public ResoucesOverlay(Drawable defaultMarker)
        {
            /*Calling boundCenterBottom() on defaultMarker makes the marker image connect
              at its Bottom center to the latitude and longitude of this Overlay Item*/
            super(boundCenterBottom(defaultMarker));
    
            markerHeight = ((BitmapDrawable) defaultMarker).getBitmap().getHeight();
    
            /* This call to populate is important. Although this does not appear in the MapView tutorial
             * on Google's Android developer site, the mapview some times crashes without this call.
             */
            populate();
        }
    
        @Override
        protected OverlayItem createItem(int i)
        {
            return mOverlays.get(i);
        }
    
        @Override
        public int size()
        {
            return mOverlays.size();
        }
    
        @Override
        public void draw(android.graphics.Canvas canvas, MapView mapView,
                boolean shadow)
        {
            super.draw(canvas, mapView, shadow);
    
            // go through all OverlayItems and draw title for each of them
            for (OverlayItem item:mOverlays)
            {
                /* Converts latitude & longitude of this overlay item to coordinates on screen.
                 * As we have called boundCenterBottom() in constructor, so these coordinates
                 * will be of the bottom center position of the displayed marker.
                 */
                GeoPoint point = item.getPoint();
                Point markerBottomCenterCoords = new Point();
                mapView.getProjection().toPixels(point, markerBottomCenterCoords);
    
                /* Find the width and height of the title*/
                TextPaint paintText = new TextPaint();
                Paint paintRect = new Paint();
    
                Rect rect = new Rect();
                paintText.setTextSize(FONT_SIZE);
                paintText.getTextBounds(item.getTitle(), 0, item.getTitle().length(), rect);
    
                rect.inset(-TITLE_MARGIN, -TITLE_MARGIN);
                rect.offsetTo(markerBottomCenterCoords.x - rect.width()/2, markerBottomCenterCoords.y - markerHeight - rect.height());
    
                paintText.setTextAlign(Paint.Align.CENTER);
                paintText.setTextSize(FONT_SIZE);
                paintText.setARGB(255, 255, 255, 255);
                paintRect.setARGB(130, 0, 0, 0);
    
                canvas.drawRoundRect( new RectF(rect), 2, 2, paintRect);
                canvas.drawText(item.getTitle(), rect.left + rect.width() / 2,
                        rect.bottom - TITLE_MARGIN, paintText);
            }
        }
    
        public void addOverlay(int latitude, int longitude, String title,
                String snippet)
        {
            OverlayItem item;
    
            GeoPoint geopoint = new GeoPoint(latitude, longitude);
            item = new OverlayItem(geopoint, title, snippet);
            mOverlays.add(item);
            populate();
    
        }
    
        public void addOverlay(OverlayItem overlayItem)
        {
            mOverlays.add(overlayItem);
            populate();
        }
    
        private int markerHeight;
        private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
    
        private static final int FONT_SIZE = 12;
        private static final int TITLE_MARGIN = 3;
    }
    

    enter image description here

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

Sidebar

Related Questions

public static void parseProfilesJson(String the_json){ try { JSONObject myjson = new JSONObject(the_json); JSONArray nameArray
listview jArray = new JSONObject(result); json = jArray.getJSONArray(mainmenu); list = (ListView) findViewById(R.id.mainmenulist); adapter =
Here is my class where I try to get into a JSONArray some data
I am trying to use JSON and HTTP client to retrieve data from a
I'm trying to pass some data from one activity to a new one but
Ok, facing the problem I can't parse my data from inside the try{} to
I can retrieve data from normal json link But I have one link which
When I try to convert an HTTP POST response to JSONArray I get the
I try to send json array to ajax (from PHP to jQuery) in my
Try to see which cast is faster (not necessary better): new c++ case or

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.