Android SDK: Build a Mall Finder App – Points of Interest

Android SDK: Build a Mall Finder App – Points of Interest

Tutorial Details
  • Technology: Android SDK
  • Difficulty: Intermediate
  • Completion Time: 1 Hour
This entry is part 2 of 2 in the series Build a Mall Finder App

This tutorial will explore how to use the Google Maps API to overlay points of interest (POI) and use the available Location Based Services on your handset to show your position relative to the POI locations available. In this case, we shall be using Shopping Malls as the POI.

In part one of this series, we covered how to use the MapView and obtain your current location by implementing the location listener. In this lesson, we will be expanding on what was done in the first tutorial and adding the overlays to show your current position and the location of some points of interest (POI). We will do this by using an external library that has already been developed by Jeff Gifelt. If you have not completed the first tutorial, I strongly advise you do so before starting this one. However, if you decide not to, you can use the source files included at the end of the last tutorial as the starting point for this one.

You should note that in the previous lesson we already covered how to get your current location. In this lesson we will be hard coding our location to Florida University (this is only for the sake of this tutorial, so we can show malls in that area).

Since we will be continuing from the last tutorial, you should go ahead and open that project.


Step 1: Displaying Location Information

The last step we completed previously was to display our current location, but let’s expand a bit on this and actually display some information about our current position, such as latitude and longitude.

This information will be displayed as white text on a semi-transparent black background near the top of the MapView.

Open the layout file (main.xml), which is located at MallFinder > res > layout > main.xml

Add the following code after the MapView closing tag, but before the closing tag of the FrameLayout:

<LinearLayout
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:id="@+id/infoLinearLayout"
    android:clickable="true"
    android:onClick="centerToCurrentLocation">
    <TableLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="30dp"
        android:background="#97000000"
        android:padding="7sp">
        <TableRow>
            <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="@string/latitude"
            android:id="@+id/latitudeText"
            android:textColor="#FFFFFF">
            </TextView>
            <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="@string/longitude"
            android:id="@+id/longitudeText"
            android:textColor="#FFFFFF">
            </TextView>
        </TableRow>
       	<TableRow>
            <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="@string/accuracy"
            android:id="@+id/accuracyText"
            android:textColor="#FFFFFF">
            </TextView>
            <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="@string/provider"
            android:id="@+id/providerText"
            android:textColor="#FFFFFF">
            </TextView>
        </TableRow>
    </TableLayout>
</LinearLayout>

You may have noticed that an onClick method was specified for the LinearLayout, this method will be used to center the MapView around the user’s current location when the semi transparent LinearLayout is tapped. This will be useful if the user decides to scroll around on the MapView and would like to quickly return their current location.

In the file above, a couple of strings were referenced (the lines that begin with android:text=”@string…”), but these strings were not created as yet, so let’s do that now.

Open the strings.xml file located at MallFinder > res > values > strings.xml and add the following lines of code.

<string name="latitude">Latitude : </string>
<string name="longitude">Longitude : </string>
<string name="accuracy">Accuracy : </string>
<string name="provider">Provider : </string>

Now that we have updated the UI, let’s update the MallFinderActivity.java class code to display our location coordinates.

Open the MallFinderActivity.java file and add the following line to the getLastLocation method:

((TextView)findViewById(R.id.providerText)).setText("Provider :" + getBestProvider());

Update the setCurrentLocation method to include the following lines:

((TextView)findViewById(R.id.latitudeText)).setText("Latitude : " + String.valueOf((int)(location.getLatitude()*1E6)));
((TextView)findViewById(R.id.longitudeText)).setText("Longitude : " +  String.valueOf((int)(location.getLongitude()*1E6)));
((TextView)findViewById(R.id.accuracyText)).setText("Accuracy : " + String.valueOf(location.getAccuracy()) + " m");

Lastly, add the following method:

public void centerToCurrentLocation(View view){
    	animateToCurrentLocation();
}

If you run the app now, you should see your current latitude, location, provider, and accuracy displayed over the MapView.
Note: if this is the first time running the app the latitude, longitude, and other locations may be blank until your phone can detect your current location. This can take some time depending on the provider being used.

Image with Current Location

Step 2: Using an External Library

We are about to begin adding the overlays onto our MapView to show our current position as well as the positions of the various places of interest. In order to this we will be using a customized BalloonItemizedOverlay class which was developed by Jeff Gifelt and is located at https://github.com/jgilfelt/android-mapviewballoons. You should note that Android has its own ItemizedOverlay class which can be used to overlay graphics onto a MapView, I chose this class over the ItemizedOverlay class because it provides a popup balloon feature when an overlay graphic is pressed, a feature which the ItemizedOverlay class does not have by default. This will also give us a chance to see how to setup and include external library projects in our own projects.

Let’s start by downloading the file. Open your web browser and navigate to https://github.com/jgilfelt/android-mapviewballoons/downloads and click on the “Download as zip” button.

After downloading, unzip the file and note the file location.

In Eclipse, Navigate to File > Import. In the new window, select “Existing Projects into Workspace” and then click next.

Importing External Library

For the “Select root directory field”, browse to the folder you unzipped the BalloonItemizedOverlay into and select it. In the Projects area only the android-mapviewsballoon project is required. However, you are free to select both projects if you would like the example project included.
Make sure the Copy Projects into workspace checkbox is selected. Click finish.

Importing External Library Step 2

You should now see the android-mapviewballoons project in the package explorer window.

Right click on the android-mapviewballoons project and select properties. A new window will pop up. On the left column, under the “type filter text” text box, click on Android on the right hand side of the window ensure the “Is Library” checkbox is selected, if it is not then select it and click Apply and then OK.

Importing External Library Step 3

You can now use this library in your existing and new projects as we are going to do now.

We are going to have our MallFinder Project, use the library that we included above. To do this, right click on the MallFinder Project in the Package Explorer Window in Eclipse, then Properties, and select Android on the left column as you did in the step above. In the right column, look for the Library area (the same area in the previous step where you selected “Is Library”), but this time click on the Add button. A new Project Selection Window will pop up. Select the android-mapviewballoons and then click OK.

Importing External Library Step 4

You should see an entry with the reference to the project. Select android-mapballoons and click Apply. Next click OK.


Step 3: Creating the Overlay Class

We are now going to create a MallOverlay class, which extends the BalloonItemizedOverlay class. Go to MallFinder > src > com.shawnbe.mallfinder. Right Click on the com.shawnbe.mallfinder in the Package Explorer window. Then select New > Class. Name the class MallOverlay, and then click Finish.

Creating Overlay Class

We need to update the MallOverlay class to extend BalloonItemizedOverlay.

Do this by updating the line:

public class MallOverlay {

to:

public class MallOverlay extends BalloonItemizedOverlay<OverlayItem> {

We also need to import a few items. To do this, add the following lines at the top of the MallOverlay.java class:

import android.graphics.drawable.Drawable;
import com.google.android.maps.MapView;
import com.google.android.maps.OverlayItem;
import com.readystatesoftware.mapviewballoons.BalloonItemizedOverlay;

Next, we will need to add a constructor and implement some of the required methods when extending the BalloonItemizedOverlay class:

Note: Eclipse allows us to easily fix errors and add unimplemented methods where applicable by notifying us of errors and suggesting fixes where possible.

For example, before we include the constructor or the needed methods you will notice that the word MallOverlay is underlined in red in the line

public class MallOverlay extends BalloonItemizedOverlay<OverlayItem> {

This indicates that there is an error. Place your cursor over the word MallOverlay and an information dialog will appear letting you know that you must define a contructor and there is one quick fix available.

Autofix Error

Click on the Add Constructor “MallOverlay(Drawable,MapView)” link and a skeleton constructor will be added for you.

Notice that the word MallOverlay is still underlined. Hover again and you will see this is because there are unimplemented methods. Click on the “add unimplemented methods” link and the two skeleton methods will be created for you.

It’s very important that you understand what is causing your errors rather than just relying on this feature, but once you understand what may be causing errors in your code. This feature can save you a lot of time and effort by not having to type out each method.

The MallOverlay class should look like this

package com.shawnbe.mallfinder;
import android.graphics.drawable.Drawable;
import com.google.android.maps.MapView;
import com.google.android.maps.OverlayItem;
import com.readystatesoftware.mapviewballoons.BalloonItemizedOverlay;
public class MallOverlay extends BalloonItemizedOverlay<OverlayItem> {
	public MallOverlay(Drawable defaultMarker, MapView mapView) {
		super(defaultMarker, mapView);
		// TODO Auto-generated constructor stub
	}
	@Override
	protected OverlayItem createItem(int i) {
		// TODO Auto-generated method stub
		return null;
	}
	@Override
	public int size() {
		// TODO Auto-generated method stub
		return 0;
	}
}

Now, we are going to add some functional code to the skeleton methods. Declare these three global variables:

private Context mContext;
private ArrayList<OverlayItem> malls = new ArrayList<OverlayItem>();
private Location currentLocation;

Update and add the methods in the MallOverlay class so they are the same as below:

public MallOverlay(Drawable defaultMarker, MapView mapView) {
	super(boundCenter(defaultMarker),mapView);
	boundCenter(defaultMarker);
	mContext = mapView.getContext();
}
@Override
protected OverlayItem createItem(int i) {
	// TODO Auto-generated method stub
	return malls.get(i);
}
@Override
	public int size() {
	// TODO Auto-generated method stub
	return malls.size();
}
public void addOverlay(OverlayItem overlay) {
    malls.add(overlay);
    populate();
}
@Override
protected boolean onBalloonTap(int index, OverlayItem item) {
	Toast.makeText(mContext, "Overlay Item " + index + " tapped!",
			Toast.LENGTH_LONG).show();
	return true;
}

We now have a class that for the most part handles the drawing of the overlays on to a MapView.


Step 4: Current Position Overlay

We will be using two pin graphics on the map overlay, a blue pin to show our current location and a red pin to show the surrounding malls.

My Location Icon
Mall Location Icon

Download these two graphics and place them in your drawable folder. Since I am dealing with an HDPI screen, I will use the Mallfinder > res > drawable-hdpi folder. You should note that when developing an application for public use since you have no idea what kind of pixel density the user’s handset will have so you should create an appropriate graphic for each of the three densities. This will prevent your graphics from having to be stretched and shrunk as this can make your graphics look different than how you intended it to look.

We will create a method that takes our current position and overlay a drawable image.

Add the method below to the MallFinderActivity class:

public void drawCurrPositionOverlay(){
	List<Overlay> overlays = mapView.getOverlays();
	overlays.remove(currPos);
    Drawable marker = getResources().getDrawable(R.drawable.me);
    currPos = new MallOverlay(marker,mapView);
    if(currentPoint!=null){
	    OverlayItem overlayitem = new OverlayItem(currentPoint, "Me", "Here I am!");
	    currPos.addOverlay(overlayitem);
	    overlays.add(currPos);
        currPos.setCurrentLocation(currentLocation);
    }
}

Also, add the following line to the onCreate method after the getLastLocation method is called and also to the end of the setCurrentLocation method.

drawCurrPositionOverlay();

Run the application and you should see the blue pin showing your current location.

MapView Showing current Location

Step 5: Adding the Mall Marker Overlays

So far in our tutorial, we have shown you how to obtain your current location and mark it using an overlay item. However, for the sake of the rest of the tutorial, we will be hard coding your current location to the Florida International University (FIU). In our example, I will be using malls around the FIU area. Rather than having you scroll to that area every time, you launch the application we will placing you at FIU.

Let’s do this now by opening the MallFinderActivity class and commenting on the first three lines of code in the setCurrentLocation method and adding these four lines of code after the commented area.

currentPoint = new GeoPoint(29647929,-82352486);
currentLocation = new Location("");
currentLocation.setLatitude(currentPoint.getLatitudeE6() / 1e6);
currentLocation.setLongitude(currentPoint.getLongitudeE6() / 1e6);

The four lines of code above should also be placed before the lines in the getLastLocation method:

if(currentLocation != null){
    	setCurrentLocation(currentLocation);
}

At this time, the complete setCurrentLocation method should be:

public void setCurrentLocation(Location location){
     /*	int currLatitude = (int) (location.getLatitude()*1E6);
    	int currLongitude = (int) (location.getLongitude()*1E6);
    	currentPoint = new GeoPoint(currLatitude,currLongitude); */
    	/*========================================================================================
    	/*The Above Code displays your correct current location, but for the sake of the demo
    	I will be hard coding your current location to the University of Florida, to get your real
    	current location, comment or delete the line of code below and uncomment the code above. */
    	currentPoint = new GeoPoint(29647929,-82352486);
    	currentLocation = new Location("");
    	currentLocation.setLatitude(currentPoint.getLatitudeE6() / 1e6);
    	currentLocation.setLongitude(currentPoint.getLongitudeE6() / 1e6);
    	((TextView)findViewById(R.id.latitudeText)).setText("Latitude : " + String.valueOf((int)(currentLocation.getLatitude()*1E6)));
    	((TextView)findViewById(R.id.longitudeText)).setText("Longitude : " +  String.valueOf((int)(currentLocation.getLongitude()*1E6)));
    	((TextView)findViewById(R.id.accuracyText)).setText("Accuracy : " + String.valueOf(location.getAccuracy()) + " m");
    	drawCurrPositionOverlay();
    }

and the getLastLocation method:

public void getLastLocation(){
    String provider = getBestProvider();
    currentLocation = locationManager.getLastKnownLocation(provider);
    /*The next 4 lines are used to hardcode our location
     * If you wish to get your current location remember to
     * comment or remove them */
    currentPoint = new GeoPoint(29647929,-82352486);
    currentLocation = new Location("");
    currentLocation.setLatitude(currentPoint.getLatitudeE6() / 1e6);
    currentLocation.setLongitude(currentPoint.getLongitudeE6() / 1e6);
    if(currentLocation != null){
        setCurrentLocation(currentLocation);
    }
    else
    {
	    Toast.makeText(this, "Location not yet acquired", Toast.LENGTH_LONG).show();
    }
    ((TextView)findViewById(R.id.providerText)).setText("Provider :" + getBestProvider());
}

Add the following method to the MallFinderActivity class, this hardcodes some shopping areas that are nearby FIU.

public void drawMalls(){
	Drawable marker = getResources().getDrawable(R.drawable.malls);
 	MallOverlay mallsPos = new MallOverlay(marker,mapView);
    	GeoPoint[] mallCoords = new GeoPoint[6];
    	//Load Some Random Coordinates in Miami, FL
    	mallCoords[0] = new GeoPoint(29656582,-82411151);//The Oaks Mall
    	mallCoords[1] = new GeoPoint(29649831,-82376347);//Creekside mall
    	mallCoords[2] = new GeoPoint(29674146,-8238905);//Millhopper Shopping Center
    	mallCoords[3] = new GeoPoint(29675078,-82322617);//Northside Shopping Center
    	mallCoords[4] = new GeoPoint(29677017,-82339761);//Gainesville Mall
    	mallCoords[5] = new GeoPoint(29663835,-82325599);//Gainesville Shopping Center
    	List<Overlay> overlays = mapView.getOverlays();
	OverlayItem overlayItem = new OverlayItem(mallCoords[0], "The Oaks Mall", "6419 W Newberry Rd, Gainesville, FL 32605");
	mallsPos.addOverlay(overlayItem);
	overlayItem = new OverlayItem(mallCoords[1], "Creekside Mall", "3501 Southwest 2nd Avenue, Gainesville, FL");
	mallsPos.addOverlay(overlayItem);
	overlayItem = new OverlayItem(mallCoords[2], "Millhopper Shopping Center", "NW 43rd St & NW 16th Blvd. Gainesville, FL");
	mallsPos.addOverlay(overlayItem);
	overlayItem = new OverlayItem(mallCoords[3], "Northside Shopping Center", "Gainesville, FL");
	mallsPos.addOverlay(overlayItem);
	overlayItem = new OverlayItem(mallCoords[4], "Gainesville Mall", "2624 Northwest 13th Street Gainesville, FL 32609-2834");
	mallsPos.addOverlay(overlayItem);
	overlayItem = new OverlayItem(mallCoords[5], "Gainesville Shopping Center", "1344 N Main St Gainesville, Florida 32601");
	mallsPos.addOverlay(overlayItem);
	overlays.add(mallsPos);
	mallsPos.setCurrentLocation(currentLocation);
}

We need to call the above method when the page loads. To do this, add the following line after the drawCurrPositionOverlay() method in the onCreate method:

drawMalls();

Run the application and you current location should be FIU and you should also see 5 red markers representing the malls around that area:

Mapview showing mall locations

Step 6: Displaying Relevant Information

Currently when you tap on one of the markers it will give you some brief information such as the name and the address of the mall. However, let’s add just a little more relevant information. We are going to display the distance to the mall when the user taps on the information balloon.

Open the MallOverlay.java file located at MallFinder > com.shawnbe.mallfinder > MallOverlay.java and add the method below. This method accepts a GeoPoint as an argument and returns a Location. In order to use the distanceTo method provided by Android we need to supply the two positions as location objects, our method below will convert a GeoPoint to a location object:

public Location convertGpToLoc(GeoPoint gp){
	Location convertedLocation = new Location("");
	convertedLocation.setLatitude(gp.getLatitudeE6() / 1e6);
	convertedLocation.setLongitude(gp.getLongitudeE6() / 1e6);
	return convertedLocation;
}

We now need to update the onBalloonTap method to calculate the distance between our location and the overlay that was tapped and display the information as a toast.

Update the onBalloonTap method to the following:

@Override
protected boolean onBalloonTap(int index, OverlayItem item) {
	String tmp = malls.get(index).getTitle();
	GeoPoint mallPoint = malls.get(index).getPoint();
	Location tmpLoc = convertGpToLoc(mallPoint);
	double distance = ((currentLocation).distanceTo(tmpLoc))*(0.000621371192);
	DecimalFormat df = new DecimalFormat("#.##");
	tmp = tmp + " is " + String.valueOf(df.format(distance)) + " miles away.";
	Toast.makeText(mContext,tmp,Toast.LENGTH_LONG).show();
	return true;
}

When you now tap on a marker, some basic information about the name and address will be displayed in a pop-up balloon. Now, if you tap on that balloon a toast will appear with your distance from the specified mall. Save your changes and run the application to try this out:

MapView displaying Location information

There it is a working MapView with overlays. Over the past two tutorials you have learned how to use the MapView object, register for an API key, get your current location, specify criteria for your preferred provider, use external libraries, animate to a position on the MapView, add overlays on various points on the map, and even add balloon pop-ups. I hope this tutorial was informative and gives you the knowledge needed to create your own location based application. Feel free to email me at shawn@shawnbe.com if something has not been explained properly and I will do my best to clarify, or if you have suggestions or general inquiries or comments feel free to share!

Series Navigation«Android SDK: Build a Mall Finder App – Mapview & Location

Note: Want to add some source code? Type <pre><code> before it and </code></pre> after it. Find out more
  • abhijeet

    Very good tutorial

    But one Q : What if i want to get All mall’s point depend on my GPS Location automatically ?? without drawMalls using

    • http://www.shawnbe.com Shawn

      Hi Abhijeet,
      If I understand your question correctly

      1. You would need to modify the getLastLocation () method in step 5.
      You would notice that in that code there is a couple of commented lines that state

      /*The next 4 lines are used to hardcode our location
      * If you wish to get your current location remember to
      * comment or remove them */

      remove the four lines of code after the comment block which is

      currentPoint = new GeoPoint(29647929,-82352486);
      currentLocation = new Location(“”);
      currentLocation.setLatitude(currentPoint.getLatitudeE6() / 1e6);
      currentLocation.setLongitude(currentPoint.getLongitudeE6() / 1e6);

      as well as in the setcurrentLocation method() you would need to remove the line

      currentPoint = new GeoPoint(29647929,-82352486);

      as indicated by the comments in the code.

      At this point your app should be getting your actual location rather than a hard coded one.

      2. Since you now have your actual location, every time you location is changed, which is whenever the onLocationChanged() method in part 1 of the tutorial is fired, you can check for Points of Interest with a specified distance from you current location and display those.

      I hope this helps answer your question.

      Shawn

  • http://www.paradevelopment.com Brendon

    Thanks for sharing your thoughts with us as they are really interesting. I am really impressed the way you accumulate this article information. I must say that this could be a great resource explaining the concept in a most suitable manner. Keep sharing such more interesting blogs.

    • http://www.shawnbe.com Shawn

      Thanks Brendon, I look forward to writing more tutorials for mobile tuts + as well as on my personal blog site.

  • http://www.devoox.com Mickael

    Nice one, thanks :)

  • http:///webweb.ca slavi

    Nice tutorial shawn! Keep writing :-)

  • Sorin

    Can you do a google places tutorial for android?:D

  • http://www.shawnbe.com Shawn

    Thanks Mickael and Slavi. Sorin, I will try to create some more tutorials and hopefully they will be published.

  • Sam

    Awesome Tutorial Shawn.. :)

    A little question from me..
    How if I want to find the nearest place from those Malls that have been registered on the map ?..

    Thank a lot before..

    • http://www.shawnbe.com Shawn

      Hi Sam,
      I am a little confused about exactly what you need to get. Is it that any point in time you would like to find the nearest mall to you? If so you can use the distanceTo function that is included in Android to check to see the shortest distance between your current location and the various points you have saved on your map. I used the distanceTo function on step 6. If you like you can email me directly so I can understand exactly what it is that you are trying to get and maybe come up with a possible solution.

  • Gilbert

    Hey thanx for the tut,,,, bt the currPos in the drawCurrPositionOverlay Method which is in the MallFinderActivity.class is giving me an errors… help.

  • Anand Citizen

    Nice tutorial…Thanx..

  • http://avilyne.com/blog Mark

    Very nice tutorial, Shawn. Thank you for putting this together, and I hope you do more of them.

    Two minor code adjustments that will probably answer Gilbert’s currPos problem posted above.

    In the MallOverlay.java, add:

    public void setCurrentLocation(Location loc) {
    this.currentLocation = loc;
    }

    And in MallFinderActivity.java, add:

    private MallOverlay currPos;

    just above the onCreate(…) method.

  • Antigoni

    Congratulation!!!Great tutorial!!!Thanks a lot!!!
    I would like to ask you something,I run the program and its ok, its the same code as yours, but in avd accuracy is always 0 meters. Any ideas?Help me please.

  • Adam

    Hi.

    Excellent tutorial. This will be very helpfull. Could you just explain how could I make show distance in meters or kilometers. i am in Europe so meters are our measure. And one more thing if you have time to maybe add part 3 how to make different POIs so that use could select if he wnats malls, howpitals, etc.

    Thank you

  • Antigoni

    Hello Adam,
    if you want location in km you should replace this line:
    double distance = ((currentLocation).distanceTo(tmpLoc))*(0.000621371192);

    with this:
    double distance = ((currentLocation).distanceTo(tmpLoc))/(1000);

    and change the word miles to km here:
    tmp = tmp + ” is ” + String.valueOf(df.format(distance)) + ” miles away.”;

    If you want metres you just write this:
    double distance = ((currentLocation).distanceTo(tmpLoc));

    • Adam

      Thanks for you reply I will try that right after I manage to make this app work since this tutorial is full of errors. Some of them are corrected in comments but eve after doing what is said to be done there is still error.

  • Adam

    Hi

    After import of library and writing all this code I can’t test app because of this errors.

    Description Resource Path Location Type
    Project ‘android-mapviewballoons’ is missing required source folder: ‘gen’ android-mapviewballoons Build path Build Path Problem

    Description Resource Path Location Type
    The container ‘Library Projects’ references non existing library ‘D:\ANDROID\soscroatia\android-mapviewballoons\bin\android-mapviewballoons.jar’ soscroatia Build path Build Path Problem

    Description Resource Path Location Type
    Unable to resolve target ‘Google Inc.:Google APIs:4′ android-mapviewballoons Unknown Android Target Problem

    I did all that is said here made it a libray. I can’t even clean project because there are all this erros. It’s like Eclipse is trying to run mapviecbaloons as a project inside a project.

    Help?

  • Adam

    Ok, so I manage to fix some things but this two errors still remain

    Description Resource Path Location Type
    The container ‘Library Projects’ references non existing library ‘D:\ANDROID\soscroatia\android-mapviewballoons\bin\android-mapviewballoons.jar’ soscroatia Build path Build Path Problem

    Description Resource Path Location Type
    The method onClick(View) of type new View.OnClickListener(){} must override a superclass method BalloonItemizedOverlay.java /android-mapviewballoons/src/com/readystatesoftware/mapviewballoons line 241 Java Problem

    The last one says to remove override from this line, I can do that but the first problem is more important.

  • Antigoni

    Please help, I have this code and i want, except from all these, to appear a message that says:
    which mall is nearest to my location. I can see the miles if i press in each mall,but i want to write that this mall is nearest to you.
    Please help me…

  • Adam

    Finally I made it to work. There were problem with .jar file. I simply downloaded that file and put it in bin folder.

    Everything works except toast with distance. Code is the same but no toast is apearing.

    • Adam

      Toast is working but you need to press the popup baloon. I will make it to show in the same time when you click marker and that will be much better.

  • umerto

    Hi, adam where you can download .jar file and fix the project? i can’t find .jar file like your mean?

    • ytz

      Try downloading API 8 from SDK manager.

  • Mohamed

    thank you very much,that is what i am searching for
    GOD BLESS YOU

  • cedric

    Hi great tuto thanks,
    Just have a question for the dialog box u have to show the adress and the name of the mall,
    how do you do that? cause i have an aplication a bit similar but i show a big ugly dialog box and i’d like to show something else.

  • Eric

    Hi, great tutorial love it.
    Btw is there anyway to change the position of the balloon?
    Example the old way is canvas.drawBitmap(bmp, screenPts.x, screenPts.y-50, null);
    where we move the marker to -50 of current Y position.
    Thanks.

  • Vegard

    Wow!

    Just what I needed! I’m still a noob in Android / java.

    I want the distance to be displayed when you first tap the icon. Not when you tap the balloon.

    To do this, I need to get the distance “variable” from the MallOverlay.java file. I can not figgure out how to do this in a simple way.

    Could somebody please show me / explain to me how I can do this?

    Thanks for a great guide. I’m going to check out the rest of this site.

  • http://ShawnBe.com Shawn

    Hi Everyone, thanks for the comments I am really sorry I did not reply sooner but I have not checked out this page in a while, I will make some time to reply and help as soon as I could.

    • James Bond

      Hi Shawn,

      Can you update the source code, I follow all the steps and I dont get it to work.
      try to redo all the steps and see that your tutorial does not work.

      I dont know how people said is a good tutorial if it doesnt run in eclipse..

      Thanks!!

  • Vegard

    Lookin forward to it :-) I’m stuck. Still learning every day! Started reading your Java intro for android.

  • sayeedarehman

    ((TextView)findViewById(R.id.latitudeText)).setText(“Latitude : ” + String.valueOf((int)(location.getLatitude()*1E6)));
    ((TextView)findViewById(R.id.longitudeText)).setText(“Longitude : ” + String.valueOf((int)(location.getLongitude()*1E6)));
    ((TextView)findViewById(R.id.accuracyText)).setText(“Accuracy : ” + String.valueOf(location.getAccuracy()) + ” m”);

    showing errors on these line …help me

  • James Bond

    This tutorial sucks!! I follow all the steps and it does not work :(

    waste of time!!!

  • murali

    How i can save current mall location into DB… pl do u any code pl sent this mail …pl…….i tried but not able to display…

  • MuraliDharan

    this code s very useful for me… thanks boss……..

    how we can save current and mall location into database sir.. if u knw anyone this code.. pl share to this mail id…………………thanks friends..

  • prashant

    I’m stuck at step 4 , it says could not find android-mapviewballoons.apk when I run the mallfinderactivity.java file.

  • timetell

    Anyone having nullpointerexception error while taping on the balloon to try to get the distance? I’m getting this…. Any help would be GREAT!!!

    Thread [ main] (Suspended (exception NullPointerException))
    ViewRoot.handleMessage(Message) line: 1932
    ViewRoot(Handler).dispatchMessage(Message) line: 99
    Looper.loop() line: 130
    ActivityThread.main(String[]) line: 3821
    Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]
    Method.invoke(Object, Object…) line: 507
    ZygoteInit$MethodAndArgsCaller.run() line: 839
    ZygoteInit.main(String[]) line: 597
    NativeStart.main(String[]) line: not available [native method]

  • https://twitter.com/deoafema Deogratious Afimani

    Awesome tutorial
    Thanks a bunch!

  • 21

    Hi, this is very great tutorial, thanks a lot. I have a question, in your tutorial, there are malls’ geo coordinate, malls’ name and description/snippet. May i replace the description/snippet with a link to a web page?

  • rahul kapoor

    Shawn nice tutorial , can u tell me where i add that in Acticity class. i am getting error that currpos is not variable.
    Add the method below to the MallFinderActivity class:

    public void drawCurrPositionOverlay(){
    List overlays = mapView.getOverlays();
    overlays.remove(currPos);
    Drawable marker = getResources().getDrawable(R.drawable.me);
    currPos = new MallOverlay(marker,mapView);
    if(currentPoint!=null){
    OverlayItem overlayitem = new OverlayItem(currentPoint, “Me”, “Here I am!”);
    currPos.addOverlay(overlayitem);
    overlays.add(currPos);
    currPos.setCurrentLocation(currentLocation);
    }
    }

  • Paulina

    Hi Shawn,

    First of all thanks for the tutorial was very helpful :)

    I have an issue with latitude and longitude, in the code latitude and longitude they are int and it’s supposed that google maps shows latitude and longitude as “23.5343456, – 42.32342412″ what means they must be double, right?

    How can I convert this coordinates from 23232242, -423452352 (int) to 32.423234233, – 23, 3434234 (double)?

    Thank you.

  • Mudassar

    Shawn, thanks for this wonderful tutorial.

    I am newbie in android, is it possible to give intent to balloon to start another activity? i tried but it does not allow me.

  • Peter

    Awesome tutorial! Extremely helpful and very useful, especially for noobs like me. Thank you! Thank you! Thank you!

  • http://mobile.tutsplus.com/tutorials/android/android-sdk-build-a-mall-finder-app-points-of-interest/ swathi

    Thank you….Bt I am getting error in MallOverlay.java on these two statements…..

    import com.readystatesoftware.mapviewballoons.BalloonItemizedOverlay;
    public class MallOverlay extends BalloonItemizedOverlay

    as The import com.readystatesoftware.mapviewballoons.BalloonItemizedOverlay cannot be resolved and
    BalloonItemizedOverlay cannot be resolved to a type…

    Plz help me out….

  • http://mobile.tutsplus.com/tutorials/android/android-sdk-build-a-mall-finder-app-points-of-interest/comment-page-1/#comment-19402 swathi

    And also an error for method “add” in MallFinderActivity.java in the method– drawCurrPositionOverlay()
    as — The method add(Overlay) in the type List is not applicable for the arguments (MallOverlay)

    overlays.add(currPos);

  • Dan

    Many thanks for this!

  • Naina

    Hii,
    A very excellent tutorial :)
    But i want to ask that if i don’t hardcode the locations on the map, that is i need all possible malls,
    does it requires saving the data in a database ???
    What should be the steps i need to perform….plz help!
    Thanks :)

  • Naina

    Hii,
    A very excellent tutorial :)
    But i want to ask that if i don’t hardcode the locations on the map, that is i need all possible malls,
    does it requires saving the data in a database ???
    What should be the steps i need to perform….plz help!
    Thanks :)

  • ewoks

    not sure why but shadow and pin in my app are not pointing to the same location.. They are kinda crossing each other in the middle.. any advice? did I miss something?

  • BauGuest

    I am getting “TextView cannot be resolved to a type” error for “((TextView)findViewById(R.id.providerText)).setText(“Provider :” + getBestProvider());” types of codes. Do you have any idea about the problem?

    • BauGuest

      Looks like I have forgotten to add android.widget.TextView class.

  • sunil

    How can you fix guys this error….

    import com.readystatesoftware.mapviewballoons.BalloonItemizedOverlay;

    public class MallOverlay extends BalloonItemizedOverlayl {