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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T13:20:47+00:00 2026-06-10T13:20:47+00:00

i have written the code for showing location of various persons on map. i

  • 0

i have written the code for showing location of various persons on map. i am parsing Json data from PHP script. i want to show icon with text on maps. my icon is showing perfectly fine but it does not shows the associated text.My code is as below. how can i show the icon with INFO on maps?

public class Maps extends MapActivity {

    private void callPolice()
    {
            Intent callintent = new Intent(Intent.ACTION_CALL);
            callintent.setData(Uri.parse("tel:6100"));
            startActivity(callintent);
    }


private MapView mapView;

JSONArray jArray;
String result = null;
InputStream is = null;
StringBuilder sb=null;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);

//button code starts here
Button panic_button = (Button) findViewById(R.id.button1);

panic_button.setOnClickListener(new View.OnClickListener() {

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost("http://xyz.com/index.php");

        try {
            // Add your data
            List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
           nameValuePairs.add(new BasicNameValuePair("uid", "4"));
           httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

            // Execute HTTP Post Request
           //Toast.makeText(this, resId, duration)
            HttpResponse response = httpclient.execute(httppost);

        } catch (ClientProtocolException e) {
            // TODO Auto-generated catch block
        } catch (IOException e) {
            // TODO Auto-generated catch block
        }
        callPolice();

    }
});
//button code ends
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy); 

mapView = (MapView) findViewById(R.id.themap);       
        mapView.setBuiltInZoomControls(true);
      mapView.setSatellite(true);
      mapView.invalidate();

 ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
//http post
try{
     HttpClient httpclient = new DefaultHttpClient();
     HttpPost httppost = new HttpPost("http://xyz/maps.php");
     httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
     HttpResponse response = httpclient.execute(httppost);
     HttpEntity entity = response.getEntity();
     is = entity.getContent();
     }catch(Exception e){
         Log.e("log_tag", "Error in http connection"+e.toString());
    }
//convert response to string
try{
      BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
       sb = new StringBuilder();
       sb.append(reader.readLine() + "\n");

       String line="0";
       while ((line = reader.readLine()) != null) {
                      sb.append(line + "\n");
        }
        is.close();
        result=sb.toString();
        }catch(Exception e){
              Log.e("log_tag", "Error converting result "+e.toString());
        }
//paring data
double LAT;
double LANG;
String INFO;
try{
      jArray = new JSONArray(result);
      JSONObject json_data=null;
      for(int i=0;i<jArray.length();i++){
             json_data = jArray.getJSONObject(i);
             LAT=json_data.getDouble("lat");
             LANG=json_data.getDouble("lon");
             INFO=json_data.getString("name");


//Overlay code
List<Overlay> mapOverlays = mapView.getOverlays();
                Drawable drawable = this.getResources().getDrawable(R.drawable.mark_red);
       // CustomItemizedOverlay itemizedOverlay = new CustomItemizedOverlay(drawable, this);
                AddItemizedOverlay itemizedOverlay = new AddItemizedOverlay(drawable, this);
        //GeoPoint point = new GeoPoint(latitudeE6, longitudeE6);
        GeoPoint point = new GeoPoint((int)(LAT * 1e6),(int)(LANG * 1e6));
        OverlayItem overlayitem = new OverlayItem(point, INFO, INFO);
        itemizedOverlay.addOverlay(overlayitem);
        mapOverlays.add(itemizedOverlay);

        MapController mapController = mapView.getController();

        mapController.animateTo(point);
        mapController.setZoom(15);


//Overlay code

         }
      }
      catch(JSONException e1){
          Toast.makeText(getBaseContext(), "No City Found" ,Toast.LENGTH_LONG).show();
      } catch (ParseException e1) {
            e1.printStackTrace();
    }
}
@Override
protected boolean isRouteDisplayed() {
    return false;
}

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

    switch (item.getItemId())
    {
    case R.id.menu_friends:
        Intent intent = new Intent(this, Friends.class);
        startActivity(intent);
        return true;

    case R.id.menu_invite:
        Intent intent1 = new Intent(this, Invite.class);
        startActivity(intent1);
        return true;

    case R.id.menu_logout:
        Intent intent2 = new Intent(this, Logout.class);
        startActivity(intent2);
        return true;


    default:
        return super.onOptionsItemSelected(item);
    }
} 
} 
  • 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-10T13:20:48+00:00Added an answer on June 10, 2026 at 1:20 pm

    Modify your AddItemizedOverlay to include the onDraw method override and also modify your constructor to include the textsize parameter:

    public class MapItemizedOverlay extends ItemizedOverlay<OverlayItem>
    {
    //member variables
    private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
    private Context mContext;
    private int mTextSize;
    
    
    public MapItemizedOverlay(Drawable defaultMarker, Context context, int textSize)
    {
        super(boundCenterBottom(defaultMarker));
        mContext = context;
        mTextSize = textSize;
    }
    
    
    //In order for the populate() method to read each OverlayItem, it will make a request to createItem(int)
    // define this method to properly read from our ArrayList
    @Override
    protected OverlayItem createItem(int i)
    {
        return mOverlays.get(i);
    }
    
    
    @Override
    public int size()
    {
        return mOverlays.size();
    }
    
    @Override
    protected boolean onTap(int index)
    {
        OverlayItem item = mOverlays.get(index);
    
        //Do stuff here when you tap, i.e. :
        AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
        dialog.setTitle(item.getTitle());
        dialog.setMessage(item.getSnippet());
        dialog.show();
    
        //return true to indicate we've taken care of it
        return true;
    }
    
    @Override
    public void draw(android.graphics.Canvas canvas, MapView mapView, boolean shadow)
    {
        super.draw(canvas, mapView, shadow);
    
        if (shadow == false)
        {
            //cycle through all overlays
            for (int index = 0; index < mOverlays.size(); index++)
            {
                OverlayItem item = mOverlays.get(index);
    
                // Converts lat/lng-Point to coordinates on the screen
                GeoPoint point = item.getPoint();
                Point ptScreenCoord = new Point() ;
                mapView.getProjection().toPixels(point, ptScreenCoord);
    
                //Paint
                Paint paint = new Paint();
                paint.setTextAlign(Paint.Align.CENTER);
                paint.setTextSize(mTextSize);
                paint.setARGB(150, 0, 0, 0); // alpha, r, g, b (Black, semi see-through)
    
                //show text to the right of the icon
                canvas.drawText(item.getTitle(), ptScreenCoord.x, ptScreenCoord.y+mTextSize, paint);
            }
        }
    }
    
    
    public void addOverlay(OverlayItem overlay)
    {
        mOverlays.add(overlay);
        populate();
    }
    
    
    public void removeOverlay(OverlayItem overlay)
    {
        mOverlays.remove(overlay);
        populate();
    }
    
    
    public void clear()
    {
        mOverlays.clear();
        populate();
    }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a code for taking JSON data from a PHP and putting
I have written the following code snippet to read data from the database :
I have written this code inside a servlet to delete certain records from three
I have written the following code for showing the version number of ghostscript: <html>
Have written Geolocation API code for android and iphone. Take reference from http://dev.w3.org/geo/api/spec-source.html .
I have a written a simple code which would display the location on the
This is the piece of code I have written: <html> <head> <script type=text/javascript src=jquery-min.js></script>
I have written code that opens 16 figures at once. Currently, they all open
I have written code in Java to access web cam,and to save image... I
I have written code to perform a function that could take a while to

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.