The title pretty much covers it. I want to use the phone's GPS to track the user's location and display a marker on the map at their location. I want this marker to be almost constantly updating its location so that if the user moves the marker will shift as well.
I can display the map fine, but I am having trouble figuring out how to use the location services. The code I am using to display the map is below.
Layout:
<?xml version="1.0" encoding="utf-8"?>
<!-- The layout for the MainMap class -->
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.SupportMapFragment"/>
Map Activity:
public class MainMap extends FragmentActivity {
GoogleMap map;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_map);
// Get a handle to the Map Fragment
map = ((SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map)).getMap();
map.setMyLocationEnabled(true);
}
private void setUpMapIfNeeded() {
// Do a null check to confirm that we have not already instantiated the map.
if (map == null) {
map = ((SupportMapFragment) getSupportFragmentManager().
findFragmentById(R.id.map)).getMap();
// Check if we were successful in obtaining the map.
if (map != null) {
// The Map is verified. It is now safe to manipulate the map.
}
}
}
}//MainMap
Any help is appreciated. Thank you.