return true; }
public boolean onOptionsItemSelectedMenuItem item { switch item.getItemId {
case R.id.home: Intent in = new IntentListPantaiActivity.this,
DashboardActivity.class; startActivityin;
return true; case R.id.exit:
Intent exit = new IntentIntent.ACTION_MAIN; exit.addCategoryIntent.CATEGORY_HOME;
exit.setFlagsIntent.FLAG_ACTIVITY_NEW_TASK; ListPantaiActivity.this.finish;
startActivityexit; return true;
default: return super.onOptionsItemSelecteditem;
} }
}
14. Kelas MyItemizedOverlay.java
package com.fredy.wisata; import java.util.ArrayList;
import android.graphics.drawable.Drawable; import android.widget.Toast;
import com.google.android.maps.ItemizedOverlay; import com.google.android.maps.OverlayItem;
public class MyItemizedOverlay extends ItemizedOverlayOverlayItem { private ArrayListOverlayItem myOverlays ;
public MyItemizedOverlayDrawable defaultMarker { superboundCenterBottomdefaultMarker;
myOverlays = new ArrayListOverlayItem; populate;
} public void addOverlayOverlayItem overlay{
myOverlays.addoverlay; populate;
} Override
protected OverlayItem createItemint i { return myOverlays.geti;
} Removes overlay item i
public void removeItemint i{ ifi = 0 myOverlays.removei;
populate; }
Handle tap events on overlay icons Override
protected boolean onTapint i{ In this case we will just put a transient Toast message on the screen
indicating that we have captured the relevant information about the overlay item. In a more serious
application one could replace the Toast with display of a customized view with the title,
snippet text, and additional features like an embedded image, video, or sound, or links to additional
information. The lat and lon variables return the coordinates of the icon that was clicked, which could
be used for custom positioning of a display view.
Universitas Sumatera Utara
String toast = myOverlays.geti.getTitle; toast += myOverlays.geti.getSnippet;
Toast.makeTextDashboardActivity.context, toast, Toast.LENGTH_LONG.show; returntrue;
} Returns present number of items in list
Override public int size {
return myOverlays.size; }
}
15. Kelas ShowTheMap.java
package com.fredy.wisata; import java.util.List;
import com.google.android.maps.GeoPoint; import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController; import com.google.android.maps.MapView;
import com.google.android.maps.Overlay; import com.google.android.maps.OverlayItem;
import android.content.Intent; import android.graphics.drawable.Drawable;
import android.os.Bundle; import android.view.KeyEvent;
import android.view.Menu; import android.view.MenuInflater;
import android.view.MenuItem; import android.view.View;
import android.view.Window; import android.view.View.OnClickListener;
import android.widget.Button; public class ShowTheMap extends MapActivity {
private static double lat; private static double lon;
private int latE6; private int lonE6;
private MapController mapControl; private GeoPoint gp;
private MapView mapView; private Button overlayButton, accessButton;
private ListOverlay mapOverlays; private Drawable drawable1, drawable2;
private MyItemizedOverlay itemizedOverlay1, itemizedOverlay2; private boolean foodIsDisplayed = false;
Define an array containing the food overlay items private OverlayItem [] bersejarahItem = {
new OverlayItem new GeoPoint3588807,98680401, Istana Maimun, \n Jl. Brigjen Katamso, Medan \n Buka setiap hari dari jam 08.00- 18.00 WIB \n Tiket Rp.5.000 –
10.000, new OverlayItem new GeoPoint3570132,98696179, Museum Negeri
Propinsi Sumatra Utara, \n Jl. H.M. Joni no. 51, Medan \n Tiket Rp 3.000, new OverlayItem new GeoPoint3601142,98669529, Rahmat International
Wildlife Museum Gallery, \n Jl. Letjen S Parman No. 309, Medan, new OverlayItem new GeoPoint354756,98699262, Mesjid Raya, \n JL.
Sisingamangarja Amaliun No. 1, Medan Terletak berhampiran Madani Hotel, new OverlayItem new GeoPoint3590734,98677011, Balai Kota Medan,
\n Jl. Balai Kota No. 1, Medan \n Telp. 62-61 452-7800, new OverlayItem new GeoPoint3582168,98672655, Gereja Tua Immanuel, \n
JL. P Diponegoro 25-27,Medan,Telp. +62 61 4515537 , };
Universitas Sumatera Utara
Define an array containing the access overlay items private OverlayItem [] accessItem = {
new OverlayItem new GeoPoint354756,98699262, Mesjid Raya, \n Mesjid Raya,
new OverlayItem new GeoPoint3590734,98677011, Balai Kota Bank Indonesia, \n Balai Kota Bank Indonesia,
new OverlayItem new GeoPoint3582168,98672655, Gereja Tua Immanuel, \n Gereja Tua Immanuel,
}; String TAG = GPStest;
Set up the array of GeoPoints defining the route int numberRoutePoints;
GeoPoint routePoints []; Dimension will be set in class RouteLoader below int routeGrade []; Index for slope of route from point i to point i+1
boolean routeIsDisplayed = false; public void onCreateBundle savedInstanceState {
super.onCreatesavedInstanceState; requestWindowFeatureWindow.FEATURE_NO_TITLE; Suppress title bar for more space
setContentViewR.layout.showthemap; Add map controller with zoom controls
mapView = MapView findViewByIdR.id.mv; mapView.setSatellitefalse;
mapView.setTrafficfalse; mapView.setBuiltInZoomControlstrue; Set android:clickable=true in main.xml
int maxZoom = mapView.getMaxZoomLevel; int initZoom = maxZoom-11;
mapControl = mapView.getController; mapControl.setZoominitZoom;
Convert latlong in degrees into integers in microdegrees latE6 = int lat1e6;
lonE6 = int lon1e6; gp = new GeoPointlatE6, lonE6;
mapControl.animateTogp; Button to control food overlay
overlayButton = ButtonfindViewByIdR.id.btn_bangunan; overlayButton.setOnClickListenernew OnClickListener{
public void onClickView v { setOverlay1;
} };
Button to control access overlay accessButton = ButtonfindViewByIdR.id.btn_air_terjun;
accessButton.setOnClickListenernew OnClickListener{ public void onClickView v {
setOverlay2; }
}; }
Methods to set map overlays. In this case we will place a small overlay image at a specified location. Place the marker image as a png file in res drawable- .
For example, the reference to R.drawable.knifefork_small below is to an image file called knifefork_small.png in the project folder res drawable-hdpi.
Can only use lower case letters a-z, numbers 0-9, ., and _ in these image file names. In this example the single overlay item is specified by drawable and the
location of the overlay item is specified by overlayitem. Display food location overlay. If not already displayed, clicking button displays
all food overlays. If already displayed successive clicks remove items one by one.
This illustrates ability to change individual overlay items dynamically at runtime.
public void setOverlay1{ int foodLength = bersejarahItem.length;
Universitas Sumatera Utara
Create itemizedOverlay2 if it doesnt exist and display all three items if foodIsDisplayed{
mapOverlays = mapView.getOverlays; drawable1 = this.getResources.getDrawableR.drawable.marker;
itemizedOverlay1 = new MyItemizedOverlaydrawable1; Display all three items at once
forint i=0; ifoodLength; i++{ itemizedOverlay1.addOverlaybersejarahItem[i];
} mapOverlays.additemizedOverlay1;
foodIsDisplayed = foodIsDisplayed; Remove each item successively with button clicks
} else { itemizedOverlay1.removeItemitemizedOverlay1.size-1;
ifitemizedOverlay1.size 1 foodIsDisplayed = false; }
Added symbols will be displayed when map is redrawn so force redraw now mapView.postInvalidate;
} Display accessibility overlay. If not already displayed, successive button clicks
display each of the three icons successively, then the next removes them all. This illustrates the
ability to change individual overlay items dynamically at runtime.
public void setOverlay2{ int accessLength = accessItem.length;
Create itemizedOverlay2 if it doesnt exist ifitemizedOverlay2 == null {
mapOverlays = mapView.getOverlays; drawable2 = this.getResources.getDrawableR.drawable.marker;
itemizedOverlay2 = new MyItemizedOverlaydrawable2; }
Add items with each click ifitemizedOverlay2.size accessLength{
itemizedOverlay2.addOverlayaccessItem[itemizedOverlay2.size]; mapOverlays.additemizedOverlay2;
Remove all items with one click } else {
forint i=0; iaccessLength; i++{ itemizedOverlay2.removeItemaccessLength-1-i;
} }
Added symbols will be displayed when map is redrawn so force redraw now mapView.postInvalidate;
} Method to insert latitude and longitude in degrees
public static void putLatLongdouble latitude, double longitude{ lat = latitude;
lon =longitude; }
This sets the s key on the phone to toggle between satellite and map view and the t key to toggle between traffic and no traffic view traffic view
relevant only in urban areas where it is reported. public boolean onKeyDownint keyCode, KeyEvent e{
ifkeyCode == KeyEvent.KEYCODE_S{ mapView.setSatellitemapView.isSatellite;
return true; } else ifkeyCode == KeyEvent.KEYCODE_T{
mapView.setTrafficmapView.isTraffic; mapControl.animateTogp; To ensure change displays immediately
} returnsuper.onKeyDownkeyCode, e;
} Required method since class extends MapActivity
Override protected boolean isRouteDisplayed {
return false; Dont display a route }
Universitas Sumatera Utara
Method to read route data from server as XML Overlay a route. This method is only executed after loadRouteData completes
on background thread. Class to implement single task on background thread without having to manage
the threads directly. Launch with new RouteLoader.executenew URLurlString. Must be launched from the UI thread and may only be invoked once. Adapted from
example in Ch. 10 of Android Wireless Application Development. Use this to do data load from network on separate thread from main user interface to prevent locking
main UI if there is network delay. public boolean onCreateOptionsMenuMenu menu {
MenuInflater inflater = getMenuInflater; inflater.inflateR.menu.opt_menu, menu;
return true; }
public boolean onOptionsItemSelectedMenuItem item { switch item.getItemId {
case R.id.home: Intent in = new IntentShowTheMap.this,
DashboardActivity.class; startActivityin;
return true; case R.id.exit:
Intent exit = new IntentIntent.ACTION_MAIN; exit.addCategoryIntent.CATEGORY_HOME;
exit.setFlagsIntent.FLAG_ACTIVITY_NEW_TASK; ShowTheMap.this.finish;
startActivityexit; return true;
default: return super.onOptionsItemSelecteditem;
} }
}
16. Kelas Splashscreen.java