1

I'm done creating an android program that adds a marker to a location. But I need to show CURRENT MY LOCATION in the MAP. I know this is done thru location based services but I don't know how to incorporate it into my program

Here is my onCreate command


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

    //map
    mapView = (MapView) findViewById(R.id.mapView);

    //zoom
    LinearLayout zoomLayout = (LinearLayout)findViewById(R.id.zoom);  
    View zoomView = mapView.getZoomControls(); 

    zoomLayout.addView(zoomView, 
        new LinearLayout.LayoutParams(
            LayoutParams.WRAP_CONTENT, 
            LayoutParams.WRAP_CONTENT)); 
    mapView.displayZoomControls(true);

    //Philippines coordinate
    mc = mapView.getController();
    String coordinates[] = {"10.952566007", "121.78921587"};
    double lat = Double.parseDouble(coordinates[0]);
    double lng = Double.parseDouble(coordinates[1]);

    p = new GeoPoint((int) (lat * 1E6), (int) (lng * 1E6));

    mc.animateTo(p);
    mc.setZoom(6); 

    mapOverlay = new MapOverlay();
    listOfOverlays = mapView.getOverlays();
    listOfOverlays.clear();
    listOfOverlays.add(mapOverlay);  

    mapView.invalidate();
}

I have an onTouchEvent that places the marker. So no problem there, the problem is I need to display my location at the start of the program. It should show a mark that says, "You are here" or something like that in the map.

p.s: I think I need to change the hardcoded point to my current location point, but i don't know how to do that :|

lulala
  • 637
  • 4
  • 12
  • 21

2 Answers2

2

In order to get the current location of your phone I use

LocationManager locationManager = (LocationManager)this.getSystemService(LOCATION_SERVICE);
Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_COARSE); String bestProvider= locationManager.getBestProvider(criteria, true); Location loc = locationManager.getLastKnownLocation(bestProvider);

define uses-permissions in the AndroidManifest.xml for these (use the fine location for other stuff)

ref. http://code.google.com/p/android-bluetooth-on-motion/source/browse/trunk/BluetoothOnMotion/src/com/elsewhat/android/onmotion/BluetoothOnMotionService.java

In my application I would like to pass a paramter to the maps intent in order for maps to show a marker, but have found no way of doing it. Creating a location overlay as suggested by Rick (who is not Fred) is probably the way to go

dparnas
  • 4,090
  • 4
  • 33
  • 52
  • when i incorporated this code in my program, it returns a null location. – lulala Feb 28 '10 at 06:50
  • weird. Have you setup the AndroidManifest.xml in the same manner as me, ref http://code.google.com/p/android-bluetooth-on-motion/source/browse/trunk/BluetoothOnMotion/AndroidManifest.xml ? – dparnas Mar 08 '10 at 16:37
0

Hello MapView shows how to place overlays. I think you want to use the MyLocationOverlay class documented in the google APIS reference to get your current location.

RickNotFred
  • 3,381
  • 2
  • 24
  • 26
  • Another good sample that does much more than what you're looking for is the friend finder app on anddev.org: http://www.anddev.org/the_friend_finder_-_mapactivity_using_gps_-_part_i_-_ii-t93.html – RickNotFred Feb 23 '10 at 13:39