Professional Documents
Culture Documents
uastest;
import android.Manifest;
import android.app.ProgressDialog;
import android.content.pm.PackageManager;
import android.location.Address;
import android.location.Geocoder;
import android.location.Location;
import android.os.Build;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GoogleApiAvailability;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.location.LocationListener;
import com.google.android.gms.location.LocationRequest;
import com.google.android.gms.location.LocationServices;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import ac.id.atmaluhur.uastest.api.ApiClient;
import ac.id.atmaluhur.uastest.api.ApiService;
import ac.id.atmaluhur.uastest.model.ListLocationModel;
import ac.id.atmaluhur.uastest.model.LocationModel;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
// Obtain the SupportMapFragment and get notified when the map is ready to
be used.
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
checkLocationPermission();
}
if (!CheckGooglePlayServices()) {
Log.d("onCreate", "Finishing test case since google Play Services are
not available");
finish();
} else {
Log.d("onCreate", "Google Play services available.");
}
SupportMapFragment mapFragment = (SupportMapFragment)
getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
/**
* Manipulates the map once available.
* This callback is triggered when the map is ready to be used.
* This is where we can add markers or lines, add listeners or move the camera.
In this case,
* we just add a marker near Sydney, Australia.
* If Google Play services is not installed on the device, the user will be
prompted to install
* it inside the SupportMapFragment. This method will only be triggered once
the user has
* installed Google Play services and returned to the app.
*/
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
mMap.getUiSettings().setMyLocationButtonEnabled(true);
mMap.getUiSettings().setZoomControlsEnabled(true);
mMap.getUiSettings().setCompassEnabled(true);
mMap.getUiSettings().setMapToolbarEnabled(true);
getAllDataLocationLatLng();
}
@Override
public void onLocationChanged(Location location) {
Log.d("onLocationChanged", "entered");
mLastLocation = location;
if (mCurrLocationMarker != null) {
mCurrLocationMarker.remove();
}
latitude = location.getLatitude();
longitude = location.getLongitude();
markerOptions.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HU
E_MAGENTA));
mCurrLocationMarker = mMap.addMarker(markerOptions);
mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
mMap.animateCamera(CameraUpdateFactory.zoomTo(11));
LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient, this);
Log.d("onLocationChanged", "Removing Location Updates");
}
}
if (!TextUtils.isEmpty(address)) {
Geocoder geocoder = new Geocoder(this);
try {
addressList = geocoder.getFromLocationName(address, 6);
if (addressList != null) {
for (int i = 0; i < addressList.size(); i++) {
Address userAddress = addressList.get(i);
LatLng latLng = new
LatLng(userAddress.getLatitude(), userAddress.getLongitude());
userMarkerOptions.position(latLng);
userMarkerOptions.title(address);
userMarkerOptions.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactor
y.HUE_ORANGE));
mMap.addMarker(userMarkerOptions);
mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
mMap.animateCamera(CameraUpdateFactory.zoomTo(10));
}
} else {
Toast.makeText(this, "Location not found...",
Toast.LENGTH_SHORT).show();
}
} catch (IOException e) {
e.printStackTrace();
}
} else {
Toast.makeText(this, "please write any location name...",
Toast.LENGTH_SHORT).show();
}
break;
}
}
@Override
public void onFailure(Call<ListLocationModel> call, Throwable t) {
dialog.dismiss();
Toast.makeText(MapsActivity.this, t.getMessage(),
Toast.LENGTH_SHORT).show();
@Override
public void onConnected(@Nullable Bundle bundle) {
@Override
public void onConnectionSuspended(int i) {
@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
@Override
public boolean onMarkerClick(Marker marker) {
return false;
}
@Override
public void onMarkerDragStart(Marker marker) {
@Override
public void onMarkerDrag(Marker marker) {
@Override
public void onMarkerDragEnd(Marker marker) {
}
}