- Beranda
- Komunitas
- Tech
- Programmer Forum
[ASK][android] gan mohon bantuannya
TS
aero.smith
[ASK][android] gan mohon bantuannya
gan mau tanya dong,
codingan ane apa yang error ya,
ko ane back dia malah searching location lagi ya bukannya ke layout sebelumnya..
maaf newbie
makasih
codingan ane apa yang error ya,
ko ane back dia malah searching location lagi ya bukannya ke layout sebelumnya..
Spoiler for code:
Code:
public class Maps extends FragmentActivity {
String filelongitude,
filelatitude,filenama;
Marker mPositionMarker;
ProgressDialog pDialog;
private GoogleMap mMap;
private LatLng userLocation;
Double destLatitude, destLongitude;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.map);
ActionBar getSupportActionBar = getActionBar();
getSupportActionBar.setDisplayHomeAsUpEnabled(true);
getSupportActionBar.setHomeButtonEnabled(true);
// menangkap file kiriman
Intent in = getIntent();
filelongitude = in.getStringExtra("longitude");
filelatitude = in.getStringExtra("latitude");
filenama = in.getStringExtra("nama");
initMap();
mMap.setMyLocationEnabled(true);
new DownloadList().execute();
}
private void CreateMenu(Menu menu)
{
menu.setQwertyMode(true);
MenuItem kembali = menu.add(0, 0, 0, "Refresh");
{
kembali.setAlphabeticShortcut('a');
kembali.setIcon(R.drawable.navigation_refresh);
}
MenuItem kemenu = menu.add(0, 1, 1, "back to home");
{
kemenu.setAlphabeticShortcut('b');
kemenu.setIcon(R.drawable.content_remove);
}
}
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case 0:
back();
return true;
case android.R.id.home:
NavUtils.navigateUpFromSameTask(this);
return true;
}
return super.onOptionsItemSelected(item);
}
private void back()
{
Intent backto = new Intent();
setResult(RESULT_OK, backto);
finish();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
CreateMenu(menu);
return true;
}
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3)
{
}
private class DownloadList extends AsyncTask<Void, Void, Void> {
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(Maps.this);
pDialog.setMessage("Tunggu Sebentar...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();
}
protected Void doInBackground(Void... unused) {
destLatitude = Double.parseDouble(filelatitude);
destLongitude = Double.parseDouble(filelongitude);
return null;
}
protected void onPostExecute(Void unused) {
pDialog.dismiss();
runOnUiThread(new Runnable() {
public void run() {
// tbudget.setText(filebudget);
}
});
addMarkerToMap(new LatLng(destLatitude, destLongitude),
false);
searchLocation();
}
}
private void initMap() {
mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
.getMap();
}
private void addMarkerToMap(LatLng point, boolean isDraggable) {
if (point == null) {
return;
}
else if(point == userLocation) {
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(point, 13));
// Flat markers will rotate when the map is rotated,
// and change perspective when the map is tilted.
CameraPosition cameraPosition = CameraPosition.builder()
.target(point)
.zoom(13)
.bearing(90)
.build();
// Animate the change in camera view over 2 seconds
mMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition),
2000, null);
}
else {
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(point, 15f));
mMap.addMarker(new MarkerOptions()
.position(point)
.draggable(isDraggable)
.title(filenama)
.icon(BitmapDescriptorFactory
.defaultMarker(BitmapDescriptorFactory.HUE_AZURE)));
}
}
private void doDrawFastestRoute(final double srcLatitude, final double srcLongitude,
double destLatitude, double destLongitude) {
DrawRoute route = new DrawRoute(srcLatitude, srcLongitude,
destLatitude, destLongitude);
route.applyTo(mMap, this, new OnPointedListener() {
@Override
public void OnDrawLine(List<Polyline> pointRoute, double distance) {
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(srcLatitude, srcLongitude), 15f));
}
});
}
private void searchLocation() {
final ProgressDialog dialog = ProgressDialog.show(this, "",
"Searching Location");
try {
LocationResult locationResult = new LocationResult() {
@Override
public void gotLocation(final Location location,
LocationType type) {
if (location == null) {
Maps.this.runOnUiThread(new Runnable() {
public void run() {
dialog.dismiss();
popUpMessage("Tidak dapat menemukan lokasi");
}
});
} else {
Maps.this.runOnUiThread(new Runnable() {
public void run() {
dialog.dismiss();
if (mMap != null) {
userLocation = new LatLng(location
.getLatitude(), location
.getLongitude());
addMarkerToMap(userLocation, false);
doDrawFastestRoute(userLocation.latitude,
userLocation.longitude,
destLatitude, destLongitude);
}
}
});
}
}
};
MyLocation myLocation = new MyLocation();
myLocation.getLocation(this, locationResult);
} catch (Exception e) {
dialog.dismiss();
popUpMessage("Tidak dapat menemukan lokasi");
}
}
private void popUpMessage(String msg) {
Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
}
}
maaf newbie
makasih
0
589
Kutip
1
Balasan
Guest
Tulis komentar menarik atau mention replykgpt untuk ngobrol seru
Urutan
Terbaru
Terlama
Guest
Tulis komentar menarik atau mention replykgpt untuk ngobrol seru
Komunitas Pilihan