map overlay sits in Map_form which extends mapactivity. I tried to
pass in the sensor value to overlay at the method below:
private final SensorListener mListener = new SensorListener()
{
public void onSensorChanged(int sensor, float[] values)
{
if (Config.LOGD) {
Log.d("", "sensorChanged (" + values[0] + ", " +
values[1] + ", " + values[2] + ")");
}
overlay.setValue(values[0]);
}
public void onAccuracyChanged(int sensor, int accuracy){}
};
But it crushes.
Below is my code for Map_Form:
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.hardware.SensorListener;
import android.hardware.SensorManager;
import android.location.Address;
import android.location.Geocoder;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.util.Config;
import android.util.Log;
import android.view.KeyEvent;
import android.widget.Toast;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;
public class Map_Form3 extends MapActivity {
private MapView map=null;
private Main_Overlay overlay = null;
private AEDMapOverlay me=null;
private double loV = 0, laV = 0, alV =0;
private Address add = null;
GeoPoint currentLocation = null;
LocationManager locationManager;
private SensorManager mSensorManager;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mSensorManager =
(SensorManager)this.getSystemService(Context.SENSOR_SERVICE);
locationManager = (LocationManager)
this.getSystemService(Context.LOCATION_SERVICE);
LocationListener locationListener = new LocationListener() {
@Override
public void onLocationChanged(Location location)
{
Canvas canvas = new Canvas();
Log.v("INFO", "onLocationchanged");
laV= location.getLatitude();
loV= location.getLongitude();
alV= location.getAltitude();
me.drawMyLocation(canvas,map, location, new
GeoPoint((int)
(location.getLatitude()*1e6),(int)(location.getLongitude()*1e6)) , 1);
//reverse geolocation
Geocoder geocoder = new
Geocoder(getApplicationContext());
try {
List<Address> addresses =
geocoder.getFromLocation(laV, loV, 1);
add = addresses.get(0);
} catch (IOException e) {
// TODO Auto-generated catch
block
e.printStackTrace();
}
}
public void onStatusChanged(String provider,
int status, Bundle
extras) {}
public void onProviderEnabled(String provider) {}
public void onProviderDisabled(String provider) {}
};
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,
0, 0, locationListener);
setContentView(R.layout.map_form3);
map=(MapView)findViewById(R.id.map);
map.getController().setZoom(17);
map.setBuiltInZoomControls(true);
map.setHapticFeedbackEnabled(true);
map.setSatellite(false);
// Drawable marker=getResources().getDrawable(R.drawable.marker);
// marker.setBounds(0, 0,
marker.getIntrinsicWidth(),marker.getIntrinsicHeight());
// map.getOverlays().add(new SitesOverlay(marker));
me=new AEDMapOverlay(this, map);
overlay = new Main_Overlay();
map.getOverlays().add(overlay);
map.getOverlays().add(me);
}
private final SensorListener mListener = new SensorListener()
{
public void onSensorChanged(int sensor, float[] values)
{
if (Config.LOGD) {
Log.d("", "sensorChanged (" + values[0] + ", " +
values[1] + ", " + values[2] + ")");
}
overlay.setValue(values[0]);
}
public void onAccuracyChanged(int sensor, int accuracy){}
};
@Override
public void onResume() {
super.onResume();
me.enableCompass();
me.enableMyLocation();
mSensorManager.registerListener(mListener,SensorManager.SENSOR_ORIENTATION,SensorManager.SENSOR_DELAY_GAME);
}
@Override
protected void onStop()
{
// if (Config.LOGD) Log.d(TAG, "onStop");
mSensorManager.unregisterListener(mListener);
super.onStop();
}
@Override
public void onPause() {
super.onPause();
me.disableCompass();
}
@Override
protected boolean isRouteDisplayed() {
return(false);
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_S) {
// map.setSatellite(!map.isSatellite());
return(true);
}
else if (keyCode == KeyEvent.KEYCODE_Z) {
map.displayZoomControls(true);
return(true);
}
return(super.onKeyDown(keyCode, event));
}
private GeoPoint getPoint(double lat, double lon) {
return(new GeoPoint((int)(lat*1000000.0),
(int)(lon*1000000.0)));
}
private class SitesOverlay extends ItemizedOverlay<OverlayItem> {
private List<OverlayItem> items=new ArrayList<OverlayItem>();
private Drawable marker=null;
public SitesOverlay(Drawable marker) {
super(marker);
this.marker=marker;
items.add(new OverlayItem(getPoint(40.748963847316034,
-73.96807193756104),
"UN", "United Nations"));
items.add(new OverlayItem(getPoint(40.76866299974387,
-73.98268461227417),
"Lincoln Center",
"Home of Jazz at Lincoln
Center"));
items.add(new OverlayItem(getPoint(40.765136435316755,
-73.97989511489868),
"Carnegie Hall",
"Where you go with
practice, practice, practice"));
items.add(new OverlayItem(getPoint(40.70686417491799,
-74.01572942733765),
"The Downtown Club",
"Original home of the Heisman Trophy"));
populate();
}
@Override
protected OverlayItem createItem(int i) {
return(items.get(i));
}
// @Override
// public void draw(Canvas canvas, MapView mapView,
//
boolean shadow) {
// super.draw(canvas, mapView, shadow);
//
// boundCenterBottom(marker);
// }
@Override
protected boolean onTap(int i) {
Toast.makeText(Map_Form3.this,
items.get(i).getSnippet(),
Toast.LENGTH_SHORT).show();
return(true);
}
@Override
public int size() {
return(items.size());
}
}
}
On Sep 14, 11:05 pm, TreKing <[email protected]> wrote:
> On Tue, Sep 14, 2010 at 4:27 AM, dadada <[email protected]> wrote:
> > since map overlay is not activity
>
> What is your map overlay contained in?
>
> ---------------------------------------------------------------------------
> ----------------------
> TreKing <http://sites.google.com/site/rezmobileapps/treking> - Chicago
> transit tracking app for Android-powered devices
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en