I'm having a slight problem, when I run the app on my phone, my moveCamera is set on my previous location (not on my current one which I'm testing it on), and so is my addCircle (set around my previous location, not my current one).
Here is my code:
public class MapDraw extends FragmentActivity {
static GoogleMap googleMap;
LatLng myPosition;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_g_maps_circle);
SupportMapFragment fm = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
googleMap = fm.getMap();
googleMap.setMyLocationEnabled(true);
LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
Criteria criteria = new Criteria();
String provider = locationManager.getBestProvider(criteria, true);
Location location = locationManager.getLastKnownLocation(provider);
if(location!=null){
double latitude = location.getLatitude();
double longitude = location.getLongitude();
LatLng latLng = new LatLng(latitude, longitude);
myPosition = new LatLng(latitude, longitude);
circleDraw(latitude,longitude);
zoomIn(latitude,longitude);
}
}
public void circleDraw(double i, double ii) {
googleMap.addCircle(new CircleOptions()
.center(new LatLng(i, ii))
.radius(1000)
.strokeColor(Color.BLACK)
.strokeWidth(2)
.fillColor(Color.argb(50, 238, 116, 116)));
}
public void zoomIn(double Lat, double Long) {
CameraUpdate center=
CameraUpdateFactory.newLatLng(new LatLng(Lat,Long));
CameraUpdate zoom = CameraUpdateFactory.zoomTo(12);
googleMap.moveCamera(center);
googleMap.animateCamera(zoom);
}
}
I want the moveCamera to be on my current location, and my circle on my current location too. Any help please? Thanks