Note that there are some explanatory texts on larger screens.

plurals
  1. POCant get my GoogleMap to animate to a point
    text
    copied!<p>So i am fairly new with writing android code and i have been reading the book "Hello, Android" the third edition by Ed Burnette. I was curious and decided to program the GPS section to a map. so i followed the code here initially. <a href="http://mobiforge.com/developing/story/using-google-maps-android" rel="nofollow">http://mobiforge.com/developing/story/using-google-maps-android</a> . in that mobiforge example he provides his own longitude and latitude. but i wanted to mix it with the GPS from the book. </p> <p>I was able to compile and run the code i wrote. However even sending the longitude and latitude via the emulator control the code just refuses to animate to and zoom in. So i am curious why my code does not animate and zoom in.</p> <p>I have tried looking through the documentation to see if i was missing anything to solve this issue. <a href="http://developer.android.com/reference/android/location/LocationManager.html" rel="nofollow">http://developer.android.com/reference/android/location/LocationManager.html</a> and code. google.com/android/add-ons/google-apis/reference/com/google/android/maps/GeoPoint.html but it all seemed to say that i had the appropriate stuff. so i don't know if I'm just missing something.</p> <pre><code>package org.example.GoogleMaps; 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.MapView.LayoutParams; import android.app.Activity; import android.location.Criteria; import android.location.LocationListener; import android.location.LocationProvider; import android.location.Location; import android.location.LocationManager; import android.os.Bundle; import android.view.View; import android.widget.LinearLayout; import android.widget.Toast; public class GoogleMaps extends MapActivity implements LocationListener { MapView mapView; MapController mc; GeoPoint p; LocationManager mgr; String best; Location location; Double lng; Double lat; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mapView = (MapView) findViewById(R.id.mapView); LinearLayout zoomLayout = (LinearLayout)findViewById(R.id.zoom); View zoomView = mapView.getZoomControls(); zoomLayout.addView(zoomView, new LinearLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); mapView.displayZoomControls(true); mgr = (LocationManager) getSystemService(LOCATION_SERVICE); Criteria criteria = new Criteria(); best = mgr.getBestProvider(criteria, true); location = mgr.getLastKnownLocation(best); dumpLocation(location); } @Override protected boolean isRouteDisplayed() { // TODO Auto-generated method stub return false; } public void onLocationChanged(Location location) { dumpLocation(location); } public void onProviderDisabled(String provider) { log("\nProvider disabled: " + provider); } public void onProviderEnabled(String provider) { log("\nProvider enabled: " + provider); } public void onStatusChanged(String provider, int status, Bundle extras) { log("\nProvider status changed: " + provider + ", status = something" + ", extras=" + extras); } private void dumpLocation(Location location) { if (location == null) log("location = null"); else { lat = location.getLatitude(); lng = location.getLongitude(); mc = mapView.getController(); p = new GeoPoint((int)(lat * 1E6), (int)(lng * 1E6)); mc.animateTo(p); mc.setZoom(15); } } private void log(String string) { Toast.makeText(this, string, 6000); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload