Posting a stack trace from your log would be extremely helpful: )

On Mar 8, 1:19 am, CMF <manf...@gmail.com> wrote:
> Hi all, I have an MapView app downloaded from internet, when I tested
> it on the simulator, everything is fine, but when I installed it on my
> phone, the app stopped unexpectedly. Here is the code
>
> public class CurrentLocationWithMap extends MapActivity {
>
>     MapView map;
>
>     MapController ctrlMap;
>     Button inBtn;
>     Button outBtn;
>     ToggleButton switchMap;
>
>     @Override
>         protected boolean isRouteDisplayed() {
>                 return false;
>         }
>
>     @Override
>     public void onCreate(Bundle savedInstanceState) {
>         super.onCreate(savedInstanceState);
>         setContentView(R.layout.main);
>
>         map = (MapView)findViewById(R.id.myMapView);
>         List<Overlay> overlays = map.getOverlays();
>         MyLocationOverlay myLocation = new
> MyLocationOverlay(this,map);
>         myLocation.enableMyLocation();
>         overlays.add(myLocation);
>
>         ctrlMap = map.getController();
>         inBtn = (Button)findViewById(R.id.in);
>         outBtn = (Button)findViewById(R.id.out);
>         switchMap = (ToggleButton)findViewById(R.id.switchMap);
>
>         OnClickListener listener = new OnClickListener() {
>             @Override
>             public void onClick(View v) {
>                 switch (v.getId()) {
>                 case R.id.in:
>                     ctrlMap.zoomIn();
>                     break;
>                 case R.id.out:
>                     ctrlMap.zoomOut();
>                     break;
>                 default:
>                     break;
>                 }
>             }
>         };
>         inBtn.setOnClickListener(listener);
>         outBtn.setOnClickListener(listener);
>
>         //=======================================
>
>         switchMap.setOnCheckedChangeListener(new
> OnCheckedChangeListener() {
>             @Override
>             public void onCheckedChanged(CompoundButton cBtn, boolean
> isChecked) {
>                 if (isChecked == true) {
>                     map.setSatellite(true);
>                 } else {
>                     map.setSatellite(false);
>                 }
>             }
>         });
>
>         LocationManager locationManager;
>         String context = Context.LOCATION_SERVICE;
>         locationManager = (LocationManager)getSystemService(context);
>         //String provider = LocationManager.GPS_PROVIDER;
>
>         Criteria criteria = new Criteria();
>         criteria.setAccuracy(Criteria.ACCURACY_FINE);
>         criteria.setAltitudeRequired(false);
>         criteria.setBearingRequired(false);
>         criteria.setCostAllowed(true);
>         criteria.setPowerRequirement(Criteria.POWER_LOW);
>         String provider = locationManager.getBestProvider(criteria,
> true);
>
>         Location location =
> locationManager.getLastKnownLocation(provider);
>         updateWithNewLocation(location);
>         locationManager.requestLocationUpdates(provider, 2000, 10,
>                         locationListener);
>     }
>    private final LocationListener locationListener = new
> LocationListener() {
>         public void onLocationChanged(Location location) {
>         updateWithNewLocation(location);
>         }
>         public void onProviderDisabled(String provider){
>         updateWithNewLocation(null);
>         }
>         public void onProviderEnabled(String provider){ }
>         public void onStatusChanged(String provider, int status,
>         Bundle extras){ }
>     };
>     private void updateWithNewLocation(Location location) {
>         String latLongString;
>         TextView myLocationText;
>         myLocationText = (TextView)findViewById(R.id.myLocationText);
>         if (location != null) {
>             double lat = location.getLatitude();
>             double lng = location.getLongitude();
>             latLongString = "Latitude:" + lat + "\nLongtitude:" + lng;
>
>             ctrlMap.animateTo(new GeoPoint((int)(lat*1E6),(int)
> (lng*1E6)));
>         } else {
>             latLongString = "Position not found";
>         }
>         myLocationText.setText("Current location:\n" +
>         latLongString);
>
>     }
>
> }
>
> <?xml version="1.0" encoding="utf-8"?>
> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/
> android"
>     android:orientation="vertical"
>     android:layout_width="fill_parent"
>     android:layout_height="fill_parent"
>     >
> <TextView
>         android:id="@+id/myLocationText"
>     android:layout_width="fill_parent"
>     android:layout_height="wrap_content"
>     />
> <LinearLayout
>     android:orientation="horizontal"
>     android:layout_width="fill_parent"
>     android:layout_height="wrap_content" >
>     <Button
>         android:id="@+id/in"
>         android:layout_width="fill_parent"
>         android:layout_height="wrap_content"
>         android:layout_weight="1"
>         android:text="Zoom in" />
>     <Button
>         android:id="@+id/out"
>         android:layout_width="fill_parent"
>         android:layout_height="wrap_content"
>         android:layout_weight="1"
>         android:text="Zoom out" />
> </LinearLayout>
> <ToggleButton
>     android:id="@+id/switchMap"
>     android:layout_width="wrap_content"
>     android:layout_height="wrap_content"
>     android:textOff="satelliteoff"
>     android:textOn="satellite on"/>
> <com.google.android.maps.MapView
>         android:id="@+id/myMapView"
>         android:layout_width="fill_parent"
>         android:layout_height="fill_parent"
>         android:clickable="true"
>         android:apiKey="0sHYAwyCrlo-VN0Au3pKZnNg6XqNUc8xf1hyyEQ"
>      />
> </LinearLayout>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to