Android: GoogleMap v2 ignores animate/move calls - google-maps-android-api-2

I have a FragmentActivity with a GoogleMap inside. It correctly receives the user location in onLocationChanged, where I try to use the user location to center the map:
#Override
public void onLocationChanged(Location loc)
{
if (centerMap && mMap != null)
{
LatLng location = new LatLng(loc.getLatitude(), loc.getLongitude());
CameraPosition pos = new CameraPosition.Builder().target(location).zoom(12).build();
CameraUpdate cu = CameraUpdateFactory.newCameraPosition(pos);
mMap.animateCamera(cu);
// centerMap = false;
Log.e(getClass().getSimpleName(), "lat = " + location.latitude + " long = " + location.longitude);
}
}
This code actually worked now and then (maybe only once), and only during a debug session where I put a breakpoint inside the if statement. I don't understand what's wrong. The onLocationChanged method gets called regularly, it logs the position it received, that implies it entered the if condition, but the map does not move an inch from the lat=0,long=0 initial position (Africa).
Any clues?
EDIT: I must have something badly broken in my code: even markers do not show up, here is how I add them to the map
mMap.addMarker(new MarkerOptions()
.position(new LatLng(lat, lng))
.title("title")
.draggable(false)
.visible(true));
and the "My location" icon is not showing up either, even if I called
mMap.setMyLocationEnabled(true);
in onCreate(). Trying to exclude martians and such, I've already updated Eclipse, ADT and all the rest to the latest available versions.

For some reason (unknown to me), moving the map initialization from onCreate() into the first invocation of onLocationChange() did the trick. Now my onCreate() is simply
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.map_activity);
}
my onStart() is:
#Override
protected void onStart()
{
super.onStart();
// Create the LocationRequest object
mLocationRequest = LocationRequest.create();
// Use high accuracy
mLocationRequest.setPriority(
LocationRequest.PRIORITY_HIGH_ACCURACY);
// Set the update interval to 5 seconds
mLocationRequest.setInterval(UPDATE_INTERVAL);
// Set the fastest update interval to 1 second
mLocationRequest.setFastestInterval(FASTEST_INTERVAL);
mLocationClient = new LocationClient(this, this, this);
mLocationClient.connect();
}
#Override
public void onConnected(Bundle arg0)
{
mLocationClient.requestLocationUpdates(mLocationRequest, this);
}
and my onLocationChange() is
#Override
public void onLocationChanged(Location loc)
{
if (mMap == null)
{
mapFragment = SupportMapFragment.newInstance();
FragmentTransaction fragmentTransaction = getSupportFragmentManager()
.beginTransaction();
fragmentTransaction.add(R.id.mapcontainer, mapFragment);
fragmentTransaction.commit();
mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
mMap.getUiSettings().setAllGesturesEnabled(true);
mMap.getUiSettings().setMyLocationButtonEnabled(true);
mMap.getUiSettings().setZoomControlsEnabled(true);
mMap.getUiSettings().setCompassEnabled(true);
mMap.setMyLocationEnabled(false);
LatLng location = new LatLng(loc.getLatitude(), loc.getLongitude());
CameraPosition pos = new CameraPosition.Builder().target(location).zoom(12).build();
CameraUpdate cu = CameraUpdateFactory.newCameraPosition(pos);
mMap.animateCamera(cu);
if (mLocationClient.isConnected())
mLocationClient.removeLocationUpdates(this);
mLocationClient.disconnect();
Log.e(getClass().getSimpleName(), "lat = " + location.latitude + " long = " + location.longitude);
}
}
It works, but now I have a different problem (the map seems to ignore touch events). I'm going to create a separate question for that.

Related

SupportMapFragmentManagers getMapAsync() does not trigger onMapReady(GoogleMap map)

I have a
public abstract class MyMapFragment implements OnMapReadyCallback
{
//
public GoogleMap googleMap;
SupportMapFragment mapFragment;
#IdRes
public abstract int getSupportMapFragId();
#Override
public void onViewCreated(View view, #Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
// http://stackoverflow.com/a/36592000/5102206
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){
// Do something for lollipop and above versions
mapFragment = (SupportMapFragment) getChildFragmentManager().findFragmentById(getSupportMapFragId());
} else {
// do something for phones running an SDK before lollipop
mapFragment = (SupportMapFragment) getFragmentManager().findFragmentById(getSupportMapFragId());
}
mapFragment.getMapAsync(this);
}
//..
#Override
public void onMapReady(GoogleMap map) {
this.googleMap = map;
}
}
According to my breakpoints onViewCreated() is called, but onMapReady() is not called (breakpoint on this.googleMap = map not triggered)
On Android 5, 6 and 7 it works fine so far and I can see the Map..
On Android 4.X (API 16 - API 19) devices my app starts up, but then it seem to freeze there... I see a white blank screen.
On Android 4.X OS devices:
1. With getFragmentManager(), the mapFragment object is null after the else condition.
2. With getChildFragmentMenager() the mapfragment seem to be valid and non-null, but onMapReady not triggered.
What am I missing here?
Note: You cannot inflate a layout into a fragment when that layout includes a . Nested fragments are only supported when added to a fragment dynamically
If you want to inflate a map in a fragment you can either do it in xml or do it in java code like this:
#Override
public void onViewCreated(View view, #Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
FragmentManager fm = getChildFragmentManager();
SupportMapFragment mapFragment = (SupportMapFragment) fm.findFragmentByTag("mapFragment");
if (mapFragment == null) {
mapFragment = new SupportMapFragment();
FragmentTransaction ft = fm.beginTransaction();
ft.add(R.id.mapFragmentContainer, mapFragment, "mapFragment");
ft.commit();
fm.executePendingTransactions();
}
mapFragment.getMapAsync(callback);
}
And also the simple container
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/mapFragmentContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
</LinearLayout>
Also, you don't need to implement the onMapReadyCallback in the class definition. Instead of callback you create a new OnMapReadyCallback() right there:
MapView.getMapAsync(new OnMapReadyCallback() {
#Override
public void onMapReady(GoogleMap mMap) {
googleMap = mMap;
}
});
You also need these
MapView mMapView;
private GoogleMap googleMap;
I hope this helps somehow !
There was an issue with a blocking thread from RxJava on main thread. So it was not an Google Maps issue.
I don't quite understand why you are nesting fragments, specially because it can cause performance issues.
If you take a look at Google Samples, the Google Maps examples uses an Activity and SupportMapFragment:
public class MapsActivityCurrentPlace extends AppCompatActivity
implements OnMapReadyCallback, ConnectionCallbacks,
OnConnectionFailedListener {
#Override
public void onMapReady(GoogleMap map) {
mMap = map;
// Use a custom info window adapter to handle multiple lines of text in the
// info window contents.
mMap.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() {
#Override
// Return null here, so that getInfoContents() is called next.
public View getInfoWindow(Marker arg0) {
return null;
}
#Override
public View getInfoContents(Marker marker) {
// Inflate the layouts for the info window, title and snippet.
View infoWindow = getLayoutInflater().inflate(R.layout.custom_info_contents,
(FrameLayout)findViewById(R.id.map), false);
TextView title = ((TextView) infoWindow.findViewById(R.id.title));
title.setText(marker.getTitle());
TextView snippet = ((TextView) infoWindow.findViewById(R.id.snippet));
snippet.setText(marker.getSnippet());
return infoWindow;
}
});
// Turn on the My Location layer and the related control on the map.
updateLocationUI();
// Get the current location of the device and set the position of the map.
getDeviceLocation();
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (savedInstanceState != null) {
mLastKnownLocation = savedInstanceState.getParcelable(KEY_LOCATION);
mCameraPosition = savedInstanceState.getParcelable(KEY_CAMERA_POSITION);
}
setContentView(R.layout.activity_maps);
mGoogleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(this /* FragmentActivity */,
this /* OnConnectionFailedListener */)
.addConnectionCallbacks(this)
.addApi(LocationServices.API)
.addApi(Places.GEO_DATA_API)
.addApi(Places.PLACE_DETECTION_API)
.build();
mGoogleApiClient.connect();
}
#Override
public void onConnected(Bundle connectionHint) {
SupportMapFragment mapFragment =
(SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
#Override
public void onConnectionFailed(#NonNull ConnectionResult result) {
Log.d(TAG, result.getErrorMessage());
}
#Override
public void onConnectionSuspended(int cause) {
Log.d(TAG, "Play services connection suspended");
}
}

Android wear - how to capture touch events

I want to capture the touch events on Android wear (I am using Samsung Gear Live) to draw the trajectory of touch. I tried to capture onTouch event and onGenericMotionEvent event as the following code, but the event is triggered only one time or sometimes does not happen while I swiping on the screen. I need more touch events (at least 5 to 6 events when I swipe left to right) to draw the trajectory. How I can capture enough touch events on Android Wear screen?
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my);
final WatchViewStub stub = (WatchViewStub) findViewById(R.id.watch_view_stub);
stub.setOnLayoutInflatedListener(new WatchViewStub.OnLayoutInflatedListener() {
#Override
public void onLayoutInflated(WatchViewStub stub) {
ViewGroup container = (ViewGroup) findViewById(R.id.container);
container.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View view, MotionEvent event) {
String s = "";
s += "action=" + event.getAction();
s += ", X=" + event.getX();
s += ", Y=" + event.getY();
Log.d(TAG, s);
return false;
}
});
container.setOnGenericMotionListener(new View.OnGenericMotionListener() {
#Override
public boolean onGenericMotion(View view, MotionEvent event) {
String s = "";
s += "action=" + event.getAction();
s += ", X=" + event.getX();
s += ", Y=" + event.getY();
Log.d(TAG, s);
return false;
}
});
}
});
}
Can you try using only:
container.setOnTouchListener(new View.OnTouchListener() {
and return true from there? You need to inform the View you consumed the event.
If you want to debug offline you can get the touch co-ordinates from adb:-
adb shell getevent

JavaFX Dragboard setContent interfering with setOnMouseDragged?

I would like to use drag and drop in JavaFX and have a feature where you can visually see the item being dragged. I've implemented what I thought would be a working solution, but there seems to be an issue with the API.
According to the API startDragAndDrop(TransferMode...) MUST be initialized inside setOnDragDetected. This is where I use a Dragboard to store content I'd like to transfer to another node.
EDIT: This appears to have something to do with the TrasferMode. If I use TransferMode.NONE there is no issue, but use of COPY, ANY, LINK always results in this problem.
But calling dragBoard.setContent(some clipboard content) only allows very small increments of movement with the mouse (a max of 4 pixels in any direction!). Removing this line of code, I can then drag the item and see it being dragged anywhere, but of course, I then can't store clipboard content.
The problem I see is that setOnMouseDragged(..) gets called before setOnDragDetected! It doesn't make much sense why setOnMouseDragged gets run before setOnDragDetected...
Is there something obvious to you in my code that's maybe causing a problem? I'd simply like to be able to see the imgView moving when dragging and be able to drop it on a target as usual, with the clipboard content.
EDIT 2: Updated code below to reflect using only Drag events, rather than Drag and Mouse events. Using both caused issues. The problem that still remains is that I'm unable to drop on a target, since using setOnDragOver makes the dragged node always right below the cursor.
protected ImageView initImageView(Image img){
final Pane ldzPane = GameBoard.getInstance().getLDZpane();
final ObjectProperty<Point2D> dragAnchor = new SimpleObjectProperty<>();
final ImageView imgView = new ImageView(img);
final DoubleProperty initX = new SimpleDoubleProperty();
final DoubleProperty initY = new SimpleDoubleProperty();
final DoubleProperty dragX = new SimpleDoubleProperty();
final DoubleProperty dragY = new SimpleDoubleProperty();
final DoubleProperty newXPosition = new SimpleDoubleProperty();
final DoubleProperty newYPosition = new SimpleDoubleProperty();
final int buffer = 3;
imgView.setOnDragDetected(new EventHandler<MouseEvent>() {
public void handle(MouseEvent event) {
initX.set(imgView.getTranslateX());
initY.set(imgView.getTranslateY());
dragAnchor.set(new Point2D(event.getSceneX(), event.getSceneY()));
ClipboardContent content = new ClipboardContent();
content.putString(RHSIconizedToken.this.tokenLookupInfo());
Dragboard db = imgView.startDragAndDrop(TransferMode.ANY);
db.setContent(content);
event.consume();
}
});
imgView.setOnDragOver(new EventHandler<DragEvent>(){
#Override
public void handle(DragEvent event) {
imgView.toFront();
dragX.set(event.getSceneX() - dragAnchor.get().getX());
dragY.set(event.getSceneY() - dragAnchor.get().getY());
imgView.setOpacity(0.5);
newXPosition.set(initX.get() + dragX.get());
newYPosition.set(initY.get() + dragY.get());
//if( (Math.abs((newXPosition.get() - ldzPane.getWidth())) <= ldzPane.getWidth() + startX + buffer) &&
// ((newXPosition.get() + startX + imgView.getImage().getWidth()+ buffer)<= ldzPane.getWidth()))
imgView.setTranslateX(newXPosition.get());
//if( (Math.abs((newYPosition.get() - ldzPane.getHeight())) <= ldzPane.getHeight() + startY + buffer) &&
// ((newYPosition.get() + startY + imgView.getImage().getHeight()+ buffer)<= ldzPane.getHeight()))
imgView.setTranslateY(newYPosition.get());
event.consume();
}
});
imgView.setOnDragDone(new EventHandler<DragEvent>() {
public void handle(DragEvent event) {
LinkedList<RHSIconizedToken> iTokens = GameBoard.getInstance().getTokenBayItokens();
if (event.getTransferMode() == TransferMode.MOVE) {
RHSIconizedToken element = iTokens.remove(index);
iTokens.add(index, new RHSIconizedToken(element.getImage(), new SourceToken("removed", "removed"), index));
imgView.setVisible(false);
GameBoard theGameBoard = GameBoard.getInstance();
GUI theGUI = GUI.getInstance();
//was this the last one removed from the rhs?
//if so we need to signal the CompileButton to be turned on!
if(theGameBoard.isRHSempty())
theGUI.enableCompileButton();
else
theGUI.disableCompileButton();
}
event.consume();
}
});
imgView.setOnMouseEntered(new EventHandler <MouseEvent>() {
public void handle(MouseEvent event) {
imgView.setEffect(new Glow(0.5));
event.consume();
}
});
imgView.setOnMouseExited(new EventHandler <MouseEvent>() {
public void handle(MouseEvent event) {
imgView.setEffect(new Glow(0.0));
imgView.setOpacity(1);
event.consume();
}
});
return imgView;
}
Java 8 is scheduled to ship with more support for visual drag and drop. DragBoard's setDragView (Image, XOffset, YOffset) method works great, and is available with the Java 8 beta.
imgView.setOnDragDetected(new EventHandler<MouseEvent>() {
public void handle(MouseEvent event) {
ClipboardContent content = new ClipboardContent();
content.putString(RHSIconizedToken.this.tokenLookupInfo());
Dragboard db = imgView.startDragAndDrop(TransferMode.ANY);
db.setDragView(image, 7, 7);
db.setContent(content);
event.consume();
}
});
I think this would help you:
DraggablePanelsExample.java
I usedd this for my Panels too, and it works for ImageView like a charm.
EDIT:
You are combining this false! You can not combine DragDetected with MouseDragged.
If you start dragging in JavaFX, the mouseevents does not get fired anymore.
If you want a Drag-Board-String then simply save you String in you class.
ps: replace DragDone with MouseReleased

Android proximity sensor giving false results

First post here, but stackoverflow has solved soooo many problems for me. This one though, I can't seem to figure out. I'm creating an android app that de-increments and TextView value by 1 with every proximity detection. For some reason, when the Activity starts or resumes (power button), it logs 2 proximity hits. I've double-checked to ensure that I'm not close enough to the detector when pushing the power button.
Here is the code:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.exercise);
//start proximity
startProximitySensor(sensorListener());
}
private SensorEventListener sensorListener(){
listener = new SensorEventListener(){
#Override
public void onAccuracyChanged(Sensor arg0, int arg1) {
// TODO Auto-generated method stub
}
#Override
public void onSensorChanged(SensorEvent event) {
if(event.sensor.getType() == Sensor.TYPE_PROXIMITY){
String maxRange = String.valueOf(mProximitySensor.getMaximumRange());
if(event.values[0] == Float.parseFloat(maxRange)){
updateTextView();
Log.i(TAG,"Proximity Sensor Reading: "+ String.valueOf(event.values[0]));
}
}
}
};
return listener;
}
private void startProximitySensor(SensorEventListener proximitySensorEventListener){
mSensorManager = (SensorManager)getSystemService(getApplicationContext().SENSOR_SERVICE);
mProximitySensor = mSensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY);
if(mProximitySensor == null){
Log.i(TAG,"No proximity sensor found!");
}else{
proximityStarted = true;
Log.i(TAG,"Proximity started");
mSensorManager.registerListener(proximitySensorEventListener,mProximitySensor,SensorManager.SENSOR_DELAY_UI);
}
}
I've managed to get around it by creating a timeStamp in onResume, and comparing that to the SystemTime generated on each sensor change. If they differ for anything less than 1 second, then the TextView won't update. This works, but I'd still like to know if I'm missing something.
Thanks in advance

Android development - GPS not working - Application hangs when co-ordinates sent

Problem Background:
I am somewhat new to Android development. All I'm trying to do, for now, is to get GPS coordinates from the GPS device of the phone and display them on Google Maps or just in a TextView, or whatever. The main task is to get them.
I've read a number of tutorials. I'm using
- Android 2.3.3
- API level 10
- Eclipse 3.6.1
- Windows 7
Problem Description :
I have written a class GeoUpdateHandler which implements LocationListener and implements its methods onLocationChange() etc. And in MyMapsActivity, I use the regular requestLocationUpdates of the LocationManager to get periodic updates.
When I run the application, I send GPS coordinates from the Emulator Control of Eclipse (Window --> Show View --> Other --> Android --> Emulator Control) to send Longitude and Latitude. As soon as the emulated device gets the coordinates, the application hangs. Nothing happens and the cursor changes to the blue circle (which signifies thinking/stuck) and nothing happens. If I use locationManager.getLastKnownLocation(String provider), it gets null. Obviously, because there IS no last known location. It gets stuck before knowing one!
I have tried sending the coordinates through telnet as well. (cmd --> telnet localhost 5554 --> geo fix . But the same thing happens.
I have tried starting the device independent of the application, sending the coordinates, and then starting the application. But the same thing happens when I run the application: it hangs.
The following code HelloItemizedOverlay is taken from Android's MapView tutorial and works fine with manually given coordinates. The problem arises when GPS location is tried to be retrieved.
public class MyMapsActivity extends MapActivity
{
private MapController mapController;
private MapView mapView;
private LocationManager locationManager;
LinearLayout linLayout;
MapView mView;
List<Overlay> mapOverlays;
Drawable drawable;
HelloItemizedOverlay itemizedOverlay;
GeoUpdateHandler handler;
Location location;
public void onCreate(Bundle bundle)
{
super.onCreate(bundle);
setContentView(R.layout.main); // bind the layout to the activity
mView = (MapView) findViewById(R.id.mapview);
mView.setBuiltInZoomControls(true);
mapOverlays = mView.getOverlays();
drawable = this.getResources().getDrawable(R.drawable.icon);
itemizedOverlay = new HelloItemizedOverlay(drawable);
mapController = mView.getController();
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
handler = new GeoUpdateHandler();
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 3000, 0, handler);
location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
GeoPoint point = new GeoPoint((int)location.getLongitude(),(int)location.getLatitude());
OverlayItem overlayitem = new OverlayItem(point, "", "");
mView.setBuiltInZoomControls(true);
itemizedOverlay.addOverlay(overlayitem);
mapOverlays.add(itemizedOverlay);
mapController.setZoom(8);
mapController.animateTo(point);
}
#Override
protected boolean isRouteDisplayed()
{
return false;
}
public class GeoUpdateHandler implements LocationListener
{
#Override
public void onLocationChanged(Location location)
{
int lat = (int) (location.getLatitude());
int lng = (int) (location.getLongitude());
GeoPoint point = new GeoPoint(lat, lng);
mapController.animateTo(point); // mapController.setCenter(point);
}
#Override
public void onProviderDisabled(String provider)
{
}
#Override
public void onProviderEnabled(String provider)
{
}
#Override
public void onStatusChanged(String provider, int status, Bundle extras)
{
}
}
#Override
protected void onResume()
{
handler = new GeoUpdateHandler();
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 5000, 0, handler);
super.onResume();
}
}
According to this, the Geopoint constructor takes (latitude * 1e6, longitude * 1e6) as parameters ; whereas you put (longitude, latitude) when calling getLastKnownLocation, and you forgot the scale factor in the other call (in onLocationChanged). Latitude and logitude are not scaled in Location objects.
Anyways, this error should only result in displaying a blue map ((0,0) being in the atlantic ocean), so there may be other problems.
Edit:
1/ in replay to your comment, if you mix up longitude and latitude, you may get an unexisting point (latitude always stays within [-90°,90°] whereas longitude can vary in [-180°,180°])
2/ there is a bug in SDK 2.3 (API level 9), which makes the emulator crash when sending mock locations. Don't know wether it is true for 2.3.3 (lvl 10), but I used 2.1u1 (lvl 7) to test.
3/ The following code works for me :
package test.testmap;
import java.util.List;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.util.Log;
import android.widget.LinearLayout;
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;
public class MyMapsActivity extends MapActivity
{
private MapController mapController;
private LocationManager locationManager;
LinearLayout linLayout;
MapView mView;
List<Overlay> mapOverlays;
Drawable drawable;
HelloItemizedOverlay itemizedOverlay;
GeoUpdateHandler handler;
Location location;
public void onCreate(Bundle bundle)
{
super.onCreate(bundle);
setContentView(R.layout.main); // bind the layout to the activity
drawable = this.getResources().getDrawable(R.drawable.icon);
itemizedOverlay = new HelloItemizedOverlay(drawable);
mView = (MapView) findViewById(R.id.mapview);
mView.setBuiltInZoomControls(true);
mapOverlays = mView.getOverlays();
mapOverlays.add(itemizedOverlay);
mapController = mView.getController();
}
#Override
protected boolean isRouteDisplayed()
{
return false;
}
public class GeoUpdateHandler implements LocationListener
{
#Override
public void onLocationChanged(Location location)
{
Log.d(this.getClass().getName(),"onLocationChanged : lat = "+location.getLatitude()+" lon = "+location.getLongitude());
int lat = (int) Math.round(location.getLatitude()*1.0e6);
int lng = (int) Math.round(location.getLongitude()*1.0e6);
GeoPoint point = new GeoPoint(lat, lng);
itemizedOverlay.addOverlay(new OverlayItem(point, "", ""));
mapController.animateTo(point);
mapController.setZoom(8);
}
#Override
public void onProviderDisabled(String provider)
{
Log.d(this.getClass().getName(),"onProviderDisabled");
}
#Override
public void onProviderEnabled(String provider)
{
Log.d(this.getClass().getName(),"onProviderEnabled");
}
#Override
public void onStatusChanged(String provider, int status, Bundle extras)
{
Log.d(this.getClass().getName(),"onStatusChanged");
}
}
#Override
protected void onResume()
{
handler = new GeoUpdateHandler();
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 5000, 0, handler);
super.onResume();
}
}