package com.example.gpssimulator;

import java.util.List;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;

import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.Menu;

public class MainActivity extends MapActivity implements LocationListener {
	List<Overlay> mapOverlays;
	
	@Override
	protected boolean isRouteDisplayed() {
	    return false;
	}
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
	    super.onCreate(savedInstanceState);
	    setContentView(R.layout.activity_main);
	    MapView mapView = (MapView) findViewById(R.id.mapview);
	    mapView.setBuiltInZoomControls(true);
	    
	    mapOverlays = mapView.getOverlays();
	    Drawable drawable = this.getResources().getDrawable(R.drawable.androidmarker);
	    MyItemizedOverlay itemizedoverlay = new MyItemizedOverlay(drawable, this);
	    
	    GeoPoint point = new GeoPoint(19240000,-99120000);
	    OverlayItem overlayitem = new OverlayItem(point, "Hola, Mundo!", "I'm in Mexico City!");
	    
	    GeoPoint point2 = new GeoPoint(35410000, 139460000);
	    OverlayItem overlayitem2 = new OverlayItem(point2, "Sekai, konichiwa!", "I'm in Japan!");
	    
	    itemizedoverlay.addOverlay(overlayitem);
	    itemizedoverlay.addOverlay(overlayitem2);
	    
	    
	    LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);   
	    lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
	    //lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
	    mapOverlays.add(itemizedoverlay);
	}

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }

	@Override
	public void onLocationChanged(Location loc) {
		// TODO Auto-generated method stub
		 //loc.getLatitude()+ " Lng: " + loc.getLongitude(),
	    mapOverlays.remove(0);
	    GeoPoint point = new GeoPoint((int)(loc.getLatitude()*1E6), (int)(loc.getLongitude()*1E6));
	    OverlayItem overlayitem = new OverlayItem(point, "Hello!", "I'm in Houston!");
	    Drawable drawable = this.getResources().getDrawable(R.drawable.androidmarker);
	    MyItemizedOverlay itemizedoverlay = new MyItemizedOverlay(drawable, this);
	    itemizedoverlay.addOverlay(overlayitem);

	    mapOverlays.add(itemizedoverlay);
	}

	@Override
	public void onProviderDisabled(String provider) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onProviderEnabled(String provider) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onStatusChanged(String provider, int status, Bundle extras) {
		// TODO Auto-generated method stub
		
	}
}
