I have a lot to do before I am finished, after 8 hours straight working on this I need to ask for help. I have managed to set up V2 maps on Android they work on my device, I do not know where to find a resource that could help me build this up to a more advanced map application, I cannot even get the users location to show. I am debugging on an Android phone which has the internet. I have read more than 10 questions on Stack overflow as well as read through some of the documentation on Google.
Here is my class so far:
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
import android.location.Location;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;
public class MainActivity extends FragmentActivity {
private GoogleMap mMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setUpMapIfNeeded();
}
@Override
protected void onResume() {
super.onResume();
setUpMapIfNeeded();
}
private void setUpMapIfNeeded() {
// Do a null check to confirm that we have not already instantiated the map.
if (mMap == null) {
// Try to obtain the map from the SupportMapFragment.
mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))
.getMap();
// Check if we were successful in obtaining the map.
if (mMap != null) {
setUpMap();
}
}
}
private void setUpMap() {
mMap.setMyLocationEnabled(true);
mMap.getMyLocation();
}
}
I need to build up to getting the users location, then allowing the user to search for places and store them, does anyone think this would be possible in V2 maps?
Many thanks!
You would need to find the user’s location via
LocationManager, as you would in any Android app. Optionally, you can feed those locations to Maps V2 via callingsetLocationSource()on yourGoogleMap.UPDATE
If you use
setMyLocationEnabled(true)onGoogleMap, you can retrieve a location viagetMyLocation()onGoogleMap. This is simpler than rolling your own location tracking, but you do not get as much control (e.g., you are not informed of movement).