1

I am developing an app and it requires to be able to show my location, display a route between two points I select, display nearby places like restaurants and cafes etc. and also should let me check-in at any place I want. To put it more simply, I need a smaller version of Google maps for my android app which would incorporate the Maps, Local, Check-in and Navigation abilities in there.

I have searched a lot and found almost nothing useful that would tell me whether I can be able to do these things or not? I just want a smaller version of Google Maps(including the Local, Navigation and Check-in functionalities) with the same layouts and graphics etc. to be present in my app. Is it possible? If yes, then could anybody please help me out?

Mohammad Sohaib
  • 577
  • 3
  • 11
  • 28
  • hi check out this links http://stackoverflow.com/q/6140433/760489, http://stackoverflow.com/q/7266589/760489, http://stackoverflow.com/q/7228379/760489 – Pratik Dec 21 '12 at 11:47
  • not helpful at all. I have to tell I'm quite new here with a very limited concept of android etc. – Mohammad Sohaib Dec 21 '12 at 11:52
  • I've somehow learnt that the Google Maps isn't Open Source. Meaning I wont't be able to get the above functionalities for my App. Is there any alternative for this? – Mohammad Sohaib Dec 21 '12 at 12:08

2 Answers2

0

I have previous found this to be quite useful. http://code.google.com/p/android-protips-location/

However, please be aware that google has recently upgraded their android map api and I am not sure if they updated this app to match.

Corey Scott
  • 2,430
  • 3
  • 28
  • 33
0

You will need to do several things.

Firstly, to incorporate Google Maps, your complete reference is available here.

In simple steps:

1 Follow the steps here: this will help add a simple google maps to your screen.

2 To be able to get your own location you will need to use the LocationListener and LocationManager in android. To do this, first implement the LocationListener in your activity.

public class LocationActivity extends Activity implements LocationListener

3 Then you need to instantiate a few settings in your onCreate() method

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

        // Get the location manager
    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    // Define the criteria how to select the provider
    Criteria criteria = new Criteria();
    provider = locationManager.getBestProvider(criteria, false);
    Location location = locationManager.getLastKnownLocation(provider);

    // Initialize the location fields
    if (location != null) {
      System.out.println("Provider " + provider + " has been selected.");
      onLocationChanged(location);
    } 
  }

4 You need to be able to request for regular location updates. Include this in your onResume() method.

@Override
  protected void onResume() {
    super.onResume();
    locationManager.requestLocationUpdates(provider, 400, 1, this);
  }

5 If the app falls into the pause cycle, these updates shouldn't need to come.

@Override
  protected void onPause() {
    super.onPause();
    locationManager.removeUpdates(this);
  }

6 Your location listener implementation from step 2 requires that you have an onLocationChanged listener, implement it:

@Override   
public void onLocationChanged(Location location) {
int lat = (int) (location.getLatitude());
int lng = (int) (location.getLongitude());
}

7 Add these two methods to be notified of the provider of your location setting - the GPS or the Network.

public void onProviderDisabled(String arg0) {
    Toast.makeText(this, "Disabled provider " + provider,
                Toast.LENGTH_SHORT).show();
}

public void onProviderEnabled(String arg0) {
    Toast.makeText(this, "Enabled new provider " + provider,
                Toast.LENGTH_SHORT).show();
}

8 Now we need to link this up to your google maps. I will show you one example of using the google maps API to be able to generate a market to show your current location. The other usages can be inferred from the API.

First create private fields in your code:

private GoogleMap mMap;
Marker m;

9 Add these in your onCreate method - this instantiates your default marker position as 0,0 latitude and longitude.

mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
                .getMap();
m = mMap.addMarker(new MarkerOptions().position(new LatLng(0, 0))
                .title("Position"));

10 In your onLocationChanged method, we need to refresh this marker as location changes. So add:

m.setPosition(new LatLng(lat, lng));
m.setTitle("Your Position");

// Move the camera instantly to marker with a zoom
// of 15.
                            mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(lat, lng), 15));

This will be a simple way of updating the marker with your position, and should be a good intro to your Google Maps and location API in android.

SalGad
  • 2,991
  • 2
  • 18
  • 25
  • I'll surely give it a read and get back to you in a while .. Thanks in advance. – Mohammad Sohaib Dec 21 '12 at 15:50
  • Usually on your android activity you will have "public class LocationActivity extends Activity" on top (replace LocationActivity with the name of your activity - probably MainActivity). You need to add the line "implements LocationListener" after it – SalGad Dec 25 '12 at 18:41
  • but i heard implements MapActivity should be used – Mohammad Sohaib Dec 26 '12 at 04:25
  • I have used it the exact way I have described and it works perfectly. Do try it – SalGad Dec 26 '12 at 17:27
  • private GoogleMap mMap; Marker m; where do u put the above code ? – Mohammad Sohaib Jan 02 '13 at 11:22
  • Im having problems with step 8 and step 9. please explain. – Mohammad Sohaib Jan 02 '13 at 11:25
  • You put the private fields code right under the line 'public class LocationActivity extends Activity implements LocationListener' and before any methods (like onCreate). Step 9 is just additional lines in your 'onCreate' method that you created earlier – SalGad Jan 03 '13 at 11:52
  • Then its probably because you haven't followed the steps to incorporate google maps to your app correctly. Please follow the link carefully - https://developers.google.com/maps/documentation/android/start#installing_the_google_maps_android_v2_api – SalGad Jan 05 '13 at 07:12