Android : Google map cannot load current location at first time loading

on Sunday, August 3, 2014


I am creating an Android application that will show the user their current location on a map. But on first time application cannot show current location marker and cannot work current location button also.i am using the following code



gps=new GPSTracker(MainActivity.this);
if(gps.canGetLocation())
{
current_latitude=gps.getLatitude();
current_longitude=gps.getLongitude();
initialiseMap();
}
else
{
gps.showSettingsAlert();
}





}

public void initialiseMap()
{

// check if map is created successfully or not
if (googleMap == null) {
Toast.makeText(getApplicationContext(),
"Sorry! unable to create maps", Toast.LENGTH_SHORT)
.show();
}
else
{

googleMap.setMyLocationEnabled(true);
googleMap.getUiSettings().setMyLocationButtonEnabled(true);




}

0 comments:

Post a Comment