This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.wisatajogja; | |
import java.util.List; | |
import com.nostra13.universalimageloader.core.ImageLoader; | |
import android.content.Context; | |
import android.view.LayoutInflater; | |
import android.view.View; | |
import android.view.ViewGroup; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class AddMapActivity extends FragmentActivity implements GoogleMap.OnMapClickListener, GoogleApiClient.ConnectionCallbacks, | |
GoogleApiClient.OnConnectionFailedListener { | |
private double lat, lng; | |
private GoogleMap mMap; // Might be null if Google Play services APK is not available. | |
private Location location; | |
private GoogleApiClient googleApiClient; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
public void onConnected(Bundle bundle) { | |
if (location == null) { | |
// get last location device | |
location = LocationServices.FusedLocationApi.getLastLocation(googleApiClient); | |
if (mMap != null) { | |
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(location.getLatitude(), location.getLongitude()), 13)); | |
mMap.addMarker(new MarkerOptions() | |
.position(new LatLng(location.getLatitude(), location.getLongitude())) | |
.title("Starting Point") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
public void onMapClick(LatLng latLng) { | |
mMap.clear(); | |
mMap.addMarker(new MarkerOptions() | |
.position(new LatLng(latLng.latitude, latLng.longitude)) | |
.title("Starting Point") | |
.icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_marker)) | |
); | |
lat = latLng.latitude; | |
lng = latLng.longitude; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@OnClick(R.id.fab) | |
public void onFabClick() { | |
Toast.makeText(this, "fab click", Toast.LENGTH_SHORT).show(); | |
Bundle data = new Bundle(); | |
data.putDouble("lat", lat); | |
data.putDouble("lng", lng); | |
Intent resultIntent = new Intent(); | |
resultIntent.putExtras(data); | |
setResult(RESULT_OK, resultIntent); | |
finish(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* hekz! | |
* Hardcode doloe gan.. | |
* forgive me ~ | |
*/ | |
private void generateLocationDummy() { | |
locations.add(new Location("Sadranan", -8.146982, 110.6076521)); | |
locations.add(new Location("Ngrenehan", -8.1235303, 110.5161231)); | |
locations.add(new Location("Indrayanti", -8.1501091, 110.6121113)); | |
locations.add(new Location("KaliBiru", -7.8017879,110.1318019)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@OnClick(R.id.btnGetRoute) | |
public void getRoute() { | |
if (!TextUtils.isEmpty(etFrom.getText())) { | |
Location loc = locations.get(spDestination.getSelectedItemPosition()); | |
Bundle data = new Bundle(); | |
data.putDouble("latAwal", lat); | |
data.putDouble("lngAwal", lng); | |
data.putDouble("latTujuan", loc.getLat()); | |
data.putDouble("lngTujuan", loc.getLng()); | |
data.putInt("status", MainActivity.FROM_NET); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void getDirections(String URL) { | |
JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, | |
URL, null, | |
new Response.Listener<JSONObject>() { | |
@Override | |
public void onResponse(JSONObject jsonObject) { | |
progressDialog.dismiss(); | |
response = new Gson().fromJson(jsonObject.toString(), com.pratamawijaya.panggilpeta.json.Response.class); | |
Log.d("debug", "" + response.getRouteList().get(0).getLegsList().get(0).getDistance()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void fetchDirection(List<Steps> stepsList) { | |
Log.d("debug", "size list awal: " + latLngList.size()); | |
for (Steps data : stepsList) { | |
// add start | |
latLngList.add(new LatLng(data.getStartLocation().getLat(), data.getStartLocation().getLng())); | |
// decode poly | |
List<LatLng> decodedPoly = Utils.decodePoly(data.getPolyline().getPoints()); | |
for (LatLng point : decodedPoly) | |
latLngList.add(new LatLng(point.latitude, point.longitude)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void drawDirectionToMap(List<LatLng> latLngList) { | |
PolylineOptions line = new PolylineOptions().width(3).color(Color.BLUE); | |
for (int i = 0; i < latLngList.size(); i++) { | |
line.add(latLngList.get(i)); | |
} | |
mMap.addPolyline(line); | |
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(latLngList.get(0).latitude, latLngList.get(0).longitude), 14)); | |
// add marker diawal | |
mMap.addMarker(new MarkerOptions() |