Click here to Skip to main content
15,920,508 members

Comments by Member 12288686 (Top 5 by date)

Member 12288686 8-Aug-16 9:10am View    
its just there setUpMapIfNeeded();

private void setUpMapIfNeeded() {
// Do a null check to confirm that we have not already instantiated the map.

if (mapFragment == null) {
// Try to obtain the map from the SupportMapFragment.

mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;

if (ActivityCompat.checkSelfPermission(MainActivity.this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(MainActivity.this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
return;
}
mMap.setMyLocationEnabled(true);


// creating GPS Class object

gps = new GPSTracker(MainActivity.this);

mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(gps.getLatitude(), gps.getLongitude()), 15.0f));



googleMap.addMarker(new MarkerOptions()
.position(new LatLng(26.89209, 75.82759))
.title("FUN N FOOD"));

// check if GPS location can get
if (gps.canGetLocation()) {
Log.d("Your Location", "latitude:" + gps.getLatitude() + ", longitude: " + gps.getLongitude());
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(gps.getLatitude(), gps.getLongitude()), 15.0f));
} else {


gpsDialog = new MaterialDialog.Builder(MainActivity.this)
.titleColor(getResources().getColor(R.color.grey))
.title("GPS Settings")
.content("GPS is not enabled. Do you want to go to settings menu?")
.positiveText("Settings")
.negativeText("Cancel")
.positiveColorRes(R.color.grey)
.negativeColorRes(R.color.grey)
.onPositive(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
startActivity(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS));
gpsDialog.dismiss();
}
})
.onNegative(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
gpsDialog.dismiss();
}
})
.show();
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(gps.getLatitude(), gps.getLongitude()), 14.0f));

}
}
});

}
}
Member 12288686 8-Aug-16 9:09am View    
Sir the gps is working fine when i launch the app for the second time. Its just that when for the very first time and it asks to turn on the location and when i press back from the gps settings to go the app the app focuses somewhere in the ocean and when i destroy the activity and run again it runs very well.
I think there is some problem in my onResume or something.
Member 12288686 16-Mar-16 2:13am View    
Yes
Member 12288686 17-Feb-16 8:02am View    
Really thanks for this answer!!
Member 12288686 16-Feb-16 12:52pm View    
Can you provide me the refernce links which could help me or is it possible using google direction api key??
Thanks for your reply