Code example for Marker

Methods: setPosition, setSnippet, setTitle

0
package com.example.simpletracker; 
 
import java.util.LinkedList; 
import java.util.List; 
 
import android.content.Context; 
import android.database.Cursor; 
import android.database.sqlite.SQLiteDatabase; 
import android.database.sqlite.SQLiteException; 
import android.os.AsyncTask; 
import android.os.Bundle; 
import android.os.Handler; 
import android.os.Message; 
import android.support.v4.app.FragmentActivity; 
import android.util.Log; 
import android.widget.Toast; 
 
import com.google.android.gms.maps.CameraUpdateFactory; 
import com.google.android.gms.maps.GoogleMap; 
import com.google.android.gms.maps.SupportMapFragment; 
import com.google.android.gms.maps.model.LatLng; 
import com.google.android.gms.maps.model.Marker; 
import com.google.android.gms.maps.model.MarkerOptions; 
 
public class ListAllTrips extends FragmentActivity { 
 
	private static final int ADD_MARKER = 1;
	private static final int SQL_QUERY_TOAST = 2;
	private Handler mHandler = null;
	private GoogleMap mTripMap;
	private List<Marker> mMakerList;
 
	/** Called when the activity is first created. */ 
	@Override 
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.show_trip_map); 
		mHandler = new Handler() {
			public void handleMessage(Message msg) {
				 
				switch (msg.what) {
				case ADD_MARKER:
					Bundle b = (Bundle) msg.obj;
					long time = b.getLong(GPSDB.GPS_TIME);
                    double lat = b.getDouble(GPSDB.GPS_LAT);
                    double lng = b.getDouble(GPSDB.GPS_LNG);
                    String addr = b.getString(GPSDB.GPS_ADDR);
                    ToastMsg(addr);
					updateMap(time, lat, lng, addr);
					break; 
				case SQL_QUERY_TOAST:
					String rest = (String)msg.obj;
					ToastMsg(rest);
					break; 
				default: 
					break; 
				} 
 
			} 
		}; 
 
		setup(); 
 
		int TripId = getIntent().getIntExtra(GPSDB.TRIP_ID, 0);
		Toast.makeText(this, " Trip Id : "+Integer.toString(TripId), Toast.LENGTH_SHORT).show();
 
		doReadTripMarkers(TripId);
	} 
 
	private void ToastMsg (String msg) {
		Toast.makeText(this, " ToastMsg : "+msg, Toast.LENGTH_SHORT).show();
	} 
	 
	@Override 
	protected void onResume() { 
		super.onResume(); 
		setup(); 
	} 
 
	@Override 
	protected void onStop() { 
		super.onStop(); 
		//mMakerList.clear(); 
	} 
 
	private void setup() { 
		try { 
			if (mTripMap == null)
				mTripMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.trip_map)).getMap();
			if(mMakerList != null) {
				mMakerList.clear();
			} else { 
				mMakerList = new LinkedList<Marker>();
			} 
		} catch (Exception e) {
			e.printStackTrace();
		} 
			 
	} 
	private void updateMap(long inTime, double inLat, double inLng, String inAddr) {
		if (mTripMap != null) {
			double lat =inLat;
			double lng = inLng;
			String strTitle = inAddr;
			 
			LatLng tempLatLng = new LatLng(lat,lng);
			String strLatLong = "( "+Double.toString(lat) +" , " +Double.toString(lat) +" )";
			Marker curMarker = mTripMap.addMarker(new MarkerOptions().position(tempLatLng).title(strTitle).snippet(strLatLong));
			if (curMarker != null) {
				curMarker.setTitle(strTitle);
				curMarker.setSnippet(strLatLong);
				curMarker.setPosition(tempLatLng);
				mMakerList.add(curMarker);
			} 
			mTripMap.moveCamera(CameraUpdateFactory.newLatLngZoom(tempLatLng, 14));
			mTripMap.animateCamera(CameraUpdateFactory.zoomTo(16), 10, null);
			 
			//+"  Id : " + Integer.toString(tripId)