0

public class MainActivity extends FragmentActivity{

private GoogleMap mMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
}

@Override
protected void onResume() {
    super.onResume();
    setUpMapIfNeeded();
}

private void setUpMapIfNeeded() {
    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.addMarker(new MarkerOptions().position(new LatLng(0, 0)).title("Marker"));
    //mMap.setMyLocationEnabled(true);
}

}

This is my Activity. I want to start my app with my current location. I looked for some codes but none have the answer that I want. Can someone tell me what I should add?

Ismail Rubad
  • 1,458
  • 2
  • 13
  • 27

2 Answers2

0

Did you try:

LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());
    CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(latLng, 10);
    map.animateCamera(cameraUpdate);
patrick
  • 71
  • 1
  • 3
  • You can: Location location = new Location(""); location.setLatitude(0.0d); location.setLongitude(0.0d); OR in the same way like you add location to marker: example: new LatLng(0, 0) (for Lat=0 and Lng=0) – patrick Feb 08 '15 at 18:31
0

Please use Android's LocationManager to get Lat/Lng with respect to your current services. Please refer to this answer that explains the usage of LocationManager.

After getting a Location object from the LocationManager, use the lat/lng to position the map like this.

Community
  • 1
  • 1
ihsan
  • 699
  • 2
  • 9
  • 26