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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T09:55:54+00:00 2026-06-16T09:55:54+00:00

I have been using this following tutorial regarding the Google Maps API and Google

  • 0

I have been using this following tutorial regarding the Google Maps API and Google Places API.

http://www.androidhive.info/2012/08/android-working-with-google-places-and-maps-tutorial/

It is very good. I have managed to display markers of nearby places on a map, and display different types of markers for different categories as well. However, I would also like to display the establishment’s phone number in an alert dialog when the user clicks on one of my markers. For this, I am using a Place Detail search.

Below, I will provide a snippet of my Map Activity code that I am having problems with.

//Map Activity OnCreate()
//Check for null nearPlaces
if(nearPlaces.results!=null)
{
    //Loop through all places
    for(Place place:nearPlaces.results)
    {

        latitude=place.geometry.location.lat;
        longitude=place.geometry.location.lng;
        placeRef=place.reference;

        new LoadDetails().execute(placeRef);

        for(String s:place.types)
        {
            if(s.contains("restaurant"))
            {
                Drawable rMarker=this.getResources().getDrawable(R.drawable.restaurant);

                //phone=lp.getPhone();
                iOverlay=new MyItemizedOverlay(rMarker,this);

                //GeoPoint to place on map
                gp=new GeoPoint((int)(latitude*1E6),(int)(longitude*1E6));

                //Map overlay item
                oItem=new OverlayItem(gp, place.name, place.vicinity+"\n"+"Rating: "+place.rating+" "+phone);

                iOverlay.addOVerlay(oItem);

                iOverlay.addOVerlay(oItem);
                mapOverlays.add(iOverlay);
            }

I have a variable String phone which I want to be the establishment’s phone number.

Here is the LoadDetails class which extends AsyncTask

private class LoadDetails extends AsyncTask<String, String, String>
{
    @Override
    protected void onPostExecute(String result) {
                if(placeDetails!=null)
                {
                    if(placeDetails.status.equals("OK"))
                    {
                        if(placeDetails.result!=null)
                        {
                            phone=placeDetails.result.formatted_phone_number;
                            Log.d("Phone #'s",phone);
                        }
                    }
                }



    }

    @Override
    protected String doInBackground(String... params) {

        String reference=params[0];
        googlePlaces=new GooglePlaces();

        try{
            placeDetails=googlePlaces.getPlaceDetails(reference);
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }


}

In OnPostExecute, variable phone is set and my LogCat shows the phone numbers of various places. However, when I go to my Map Activity on my phone, and click a marker of a restaurant, the variable phone is always null. How do I fix this?

Any help would be great.

Thanks in advance.

EDIT: Entire MapActivity

public class Map extends MapActivity{

MapView mapView;
MapController mc;
GeoPoint gp, fGP;
List<Overlay> mapOverlays;
OverlayItem oItem;
MyItemizedOverlay iOverlay;

String placeRef,phone,placePhone;
double latitude,longitude;
double user_lat,user_long;
double friendLat,friendLong;
String userName,friendName,userStatus,userPhoneNumber;

//Nearest Places
PlacesList nearPlaces;

GooglePlaces googlePlaces;

PlaceDetails placeDetails;

@Override
protected void onCreate(Bundle arg0) {
    // TODO Auto-generated method stub
    super.onCreate(arg0);
    setContentView(R.layout.map);


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

    mc=mapView.getController();

    Intent i=getIntent();

    if (i!=null)
    {
    //Receive User's Lat and Long   
    user_lat=i.getDoubleExtra("userLAT", 0);
    user_long=i.getDoubleExtra("userLONG",0);

    userPhoneNumber=i.getStringExtra("userNUMBER");

    //Get User's Status they posted
    userStatus=i.getStringExtra("STATUS");
    //Get User's Name
    userName=i.getStringExtra("userNAME");

    //Receive Friend's Lat and Long

    friendLat=i.getDoubleExtra("friendLAT", 0);
    friendLong=i.getDoubleExtra("friendLong",0);


    //Obtain nearPlaces List from Main Activity
    nearPlaces=(PlacesList) i.getSerializableExtra("userNearPlaces");


    friendName=i.getStringExtra("friendNAME");
    Log.d("Map", userName+ " " +user_lat + " " + user_long);
    Log.d("Map2", friendName+ " " + friendLat + " " + friendLat);
    gp=new GeoPoint((int)(user_lat*1E6),(int)(user_long*1E6));

    //Friend's GeoPoint
    fGP=new GeoPoint((int)(friendLat*1E6),(int)(friendLong*1E6));

    }

    mapOverlays=mapView.getOverlays();
    Drawable marker=this.getResources().getDrawable(R.drawable.you);


    iOverlay=new MyItemizedOverlay(marker, this);
    oItem=new OverlayItem(gp,"Your Location, "+userName,userStatus);

    iOverlay.addOVerlay(oItem);
    mapOverlays.add(iOverlay);


    Drawable fMarker=this.getResources().getDrawable(R.drawable.smiley);

    iOverlay=new MyItemizedOverlay(fMarker,this);

    //Add friend marker to the map
    oItem=new OverlayItem(fGP,friendName+"'s Location", "This is your friend");
    iOverlay.addOVerlay(oItem);
    mapOverlays.add(iOverlay);

    //Check for null nearPlaces
    if(nearPlaces.results!=null)
    {
        //Loop through all places
        for(Place place:nearPlaces.results)
        {

            latitude=place.geometry.location.lat;
            longitude=place.geometry.location.lng;
            placeRef=place.reference;
            placePhone=place.phone;

            new LoadDetails().execute(placeRef);

            for(String s:place.types)
            {
                if(s.contains("restaurant"))
                {
                    Drawable rMarker=this.getResources().getDrawable(R.drawable.restaurant);

                    //phone=lp.getPhone();
                    iOverlay=new MyItemizedOverlay(rMarker,this);

                    //GeoPoint to place on map
                    gp=new GeoPoint((int)(latitude*1E6),(int)(longitude*1E6));

                    //Map overlay item
                    oItem=new OverlayItem(gp, place.name, place.vicinity+"\n"+"Rating: "+place.rating+" "+placePhone);

                    iOverlay.addOVerlay(oItem);

                    iOverlay.addOVerlay(oItem);
                    mapOverlays.add(iOverlay);
                }

                if((s.contains("cafe"))||place.name.contains("cafe"))
                {
                    Drawable cafeMarker=this.getResources().getDrawable(R.drawable.cafe);

                    iOverlay=new MyItemizedOverlay(cafeMarker,this);
                    //GeoPoint to place on map
                    gp=new GeoPoint((int)(latitude*1E6),(int)(longitude*1E6));

                    //Map overlay item
                    oItem=new OverlayItem(gp, place.name, place.vicinity+"\n"+"Rating: "+place.rating);

                    iOverlay.addOVerlay(oItem);

                    iOverlay.addOVerlay(oItem);
                    mapOverlays.add(iOverlay);

                }

                else if((s.contains("liquor_store"))||place.name.contains("liquors"))
                {
                    Drawable barMarker=this.getResources().getDrawable(R.drawable.bar);

                    iOverlay=new MyItemizedOverlay(barMarker,this);
                    //GeoPoint to place on map
                    gp=new GeoPoint((int)(latitude*1E6),(int)(longitude*1E6));

                    //Map overlay item
                    oItem=new OverlayItem(gp, place.name, place.vicinity+"\n"+"Rating: "+place.rating);

                    iOverlay.addOVerlay(oItem);

                    iOverlay.addOVerlay(oItem);
                    mapOverlays.add(iOverlay);

                }

                else if(s.contains("department_store")||s.contains("clothing_store")||s.contains("convenience_store"))
                {
                    Drawable shopMarker=this.getResources().getDrawable(R.drawable.mall);

                    iOverlay=new MyItemizedOverlay(shopMarker,this);
                    //GeoPoint to place on map
                    gp=new GeoPoint((int)(latitude*1E6),(int)(longitude*1E6));

                    //Map overlay item
                    oItem=new OverlayItem(gp, place.name, place.vicinity+"\n"+"Rating: "+place.rating);

                    iOverlay.addOVerlay(oItem);

                    iOverlay.addOVerlay(oItem);
                    mapOverlays.add(iOverlay);

                }

                else if(s.contains("hospital"))
                {
                    Drawable hMarker=this.getResources().getDrawable(R.drawable.hospital);

                    iOverlay=new MyItemizedOverlay(hMarker,this);
                    //GeoPoint to place on map
                    gp=new GeoPoint((int)(latitude*1E6),(int)(longitude*1E6));

                    //Map overlay item
                    oItem=new OverlayItem(gp, place.name, place.vicinity+"\n"+"Rating: "+place.rating);

                    iOverlay.addOVerlay(oItem);

                    iOverlay.addOVerlay(oItem);
                    mapOverlays.add(iOverlay);

                }

                else if(s.contains("movie_theater"))
                {
                    Drawable movieMarker=this.getResources().getDrawable(R.drawable.movierental);

                    iOverlay=new MyItemizedOverlay(movieMarker,this);
                    //GeoPoint to place on map
                    gp=new GeoPoint((int)(latitude*1E6),(int)(longitude*1E6));

                    //Map overlay item
                    oItem=new OverlayItem(gp, place.name, place.vicinity+"\n"+"Rating: "+place.rating);

                    iOverlay.addOVerlay(oItem);

                    iOverlay.addOVerlay(oItem);
                    mapOverlays.add(iOverlay);

                }

                else if(s.contains("pharmacy"))
                {
                    Drawable pMarker=this.getResources().getDrawable(R.drawable.pharmacy);

                    iOverlay=new MyItemizedOverlay(pMarker,this);
                    //GeoPoint to place on map
                    gp=new GeoPoint((int)(latitude*1E6),(int)(longitude*1E6));

                    //Map overlay item
                    oItem=new OverlayItem(gp, place.name, place.vicinity+"\n"+"Rating: "+place.rating);

                    iOverlay.addOVerlay(oItem);

                    iOverlay.addOVerlay(oItem);
                    mapOverlays.add(iOverlay);

                }
                else if(s.contains("hair_care"))
                {
                    Drawable bMarker=this.getResources().getDrawable(R.drawable.barber);

                    iOverlay=new MyItemizedOverlay(bMarker,this);
                    //GeoPoint to place on map
                    gp=new GeoPoint((int)(latitude*1E6),(int)(longitude*1E6));

                    //Map overlay item
                    oItem=new OverlayItem(gp, place.name, place.vicinity+"\n"+"Rating: "+place.rating);

                    iOverlay.addOVerlay(oItem);

                    iOverlay.addOVerlay(oItem);
                    mapOverlays.add(iOverlay);

                }

            }


        }
    }

    mapView.getController();

    mc.animateTo(gp);
    mc.setZoom(15);
    mc.setCenter(gp);

    mapView.invalidate();
}



@Override
protected boolean isRouteDisplayed() {
    // TODO Auto-generated method stub
    return false;
}

private class LoadDetails extends AsyncTask<String, String, String>
{
    @Override
    protected void onPostExecute(String result) {
        placePhone=result;

                    //My Logcat shows phone numbers being assigned to placePhone
        Log.d("placePhone",placePhone); 

    }

    @Override
    protected String doInBackground(String... params) {

        String reference=params[0];
        googlePlaces=new GooglePlaces();

        try{
            placeDetails=googlePlaces.getPlaceDetails(reference);
        }catch (Exception e){
            e.printStackTrace();
        }
        if(placeDetails!=null)
        {
            if(placeDetails.status.equals("OK"))
            {
                if(placeDetails.result!=null)
                {
                    phone=placeDetails.result.formatted_phone_number;

                }
            }
        }
        return phone;
    }


}

private class MyItemizedOverlay extends ItemizedOverlay<OverlayItem>
{
    private ArrayList<OverlayItem> mOverlays=new ArrayList<OverlayItem>();
    Context mContext;

    public MyItemizedOverlay(Drawable marker) {
        super(boundCenterBottom(marker));
    }

    public MyItemizedOverlay(Drawable marker,Context context) {
        super(boundCenterBottom(marker));
        mContext=context;
    }

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

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

    public void addOVerlay(OverlayItem overlay)
    {
        mOverlays.add(overlay);
        populate();
    }


    @Override
    public boolean onTap(int i) {

        OverlayItem item= mOverlays.get(i);
        AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
        dialog.setTitle(item.getTitle());
        dialog.setMessage(item.getSnippet());


        if(item.getTitle().contains("Location"))
        {
        dialog.setNegativeButton("Send SMS", new OnClickListener() {

            public void onClick(DialogInterface dialog, int which) {
                Intent smsIntent=new Intent(Intent.ACTION_SENDTO);
                smsIntent.addCategory(Intent.CATEGORY_DEFAULT);
                smsIntent.setType("vnd.android-dir/mms-sms");
                smsIntent.setData(Uri.parse("sms:"+userPhoneNumber));
                startActivity(smsIntent);

            }
        });

        dialog.setPositiveButton("Call", new OnClickListener() {

            public void onClick(DialogInterface dialog, int which) {
                String uri="tel:"+userPhoneNumber.trim();
                Intent callIntent=new Intent(Intent.ACTION_CALL);
                callIntent.setData(Uri.parse(uri));
                startActivity(callIntent);

            }
        });
        }
        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-16T09:55:55+00:00Added an answer on June 16, 2026 at 9:55 am
    oItem=new OverlayItem(gp, place.name, place.vicinity+"\n"+"Rating: "+place.rating+" "+ place.formatted_phone_number);
    

    try this place.formatted_phone_number

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

Sidebar

Related Questions

I have been learning RESTful webservices following this tutorial http://www.vogella.de/articles/REST/article.html . As I understand,
I have been following this tutorial series for OpenGL : GLUT : http://www.lighthouse3d.com/opengl/glut/ I
I have been following the tutorial http://www.burlingtontelecom.net/~ashawley/rcs/tutorial.html on how to work with files using
Using this tutorial: http://www.codeproject.com/Articles/105273/Create-RESTful-WCF-Service-API-Step-By-Step-Guide I can get a Directory Listing to display when I
I am new to WP7 programming and I have been following this tutorial http://weblogs.asp.net/scottgu/archive/2010/03/18/building-a-windows-phone-7-twitter-application-using-silverlight.aspx
I have been following this tutorial, http://ruby.railstutorial.org/chapters/modeling-users?version=3.2#top , which I find great, but it
I have been following this tutorial, http://ruby.railstutorial.org/chapters/modeling-users?version=3.2#top , and I tried this in the
I have been using an API to do some work. This is how I
I have been using Entity Framework CTP with Code-First as in this tutorial by
I am using Rails 3.1 and have been using this railscast tutorial to implement

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.