0

In my application I am using Google map API v2. I disabled the My Location Button using map.setMyLocationEnabled(false); and I wanted to add new button to do the same job. How can I use another button to show my current location in the same way as My Location Button would do? Reason: In my application I wanted to use the action Bar overlay as in the original Maps Application. But when I do this My Location Button goes under the action bar. so i had to remove the default my Location button and put my own. now I don't how to move the map to my current location when i click new button. Please Help. I am new to Google maps. Thanks in advance.

2 Answers2

0

Have a look at this it mite help you with your project.

http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/2.2_r1.1/android/location/Location.java

coolcat
  • 79
  • 9
  • Thank you for your quick response. My situation is that i wan t the full functionality of the My Location button but i cant use it. is there any other way to do this? –  Jul 26 '13 at 15:37
  • Can i ask why you have disabled you Location Button and then want to add a second Button that does the same as the first...Am sorry if i missing you point...I think you'll have a better chance if you make you Question a little clearer..As some people will down vote you for this reason..hope it helps – coolcat Jul 26 '13 at 15:41
  • in my application i wanted to have an overlayed action bar. when i do this my Loction button goes under the action bar making it useless. so i did this. Thanks for your advice. –  Jul 26 '13 at 15:48
  • http://stackoverflow.com/questions/10444153/android-statusbar-overlay-with-actionbar maybe this mite help...hope you can get round this good luck – coolcat Jul 26 '13 at 15:54
  • link caido esta respuesta deberia ser eliminada? – Bruno Sosa Fast Tag Jul 18 '18 at 23:47
0

did this myself too, but creating my own header bar and adding a new button. The following code might help (no XML attached, you can sort that yourself). Within your activity add this method:

public GeoPoint where(ArrayList<String> coordinates) {
    double lat = Double.parseDouble((String) coordinates.get(0));
    double lng = Double.parseDouble((String) coordinates.get(1));
    GeoPoint p = new GeoPoint((int) (lat * 1E6), (int) (lng * 1E6));
    return p;
}

Then, in the onCreate, add something like this, where you already have locationManager etc. instantiated:

final Button phoneLocButton = (Button) findViewById(R.id.HomeButtonG);
    phoneLocButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            try {
                locationManager = (LocationManager) getSystemService(context);
                bestProvider = locationManager.getBestProvider(c, true);
                loc = locationManager.getLastKnownLocation(bestProvider);
                if (loc != null) {
                    coords.clear();
                    coords.add("" + loc.getLatitude());
                    coords.add("" + loc.getLongitude());
                }
                mc.animateTo(where(coords));
            } catch (java.lang.IllegalStateException ill) {
                Toast.makeText(getBaseContext(),
                        "Waiting for location fix...", Toast.LENGTH_SHORT)
                        .show();
            }
        }
    });

Hope this helps. I have additional code that centers the map and plonks a pin on it, but this should get you going?

iaindownie
  • 1,046
  • 12
  • 28
  • Thanks a lot... I thing this will help me...if possible can you share some code regarding this? –  Jul 26 '13 at 16:13