2011-04-24 63 views
-2
package ntryn.n; 


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.Toast; 

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 ntryn extends MapActivity 

{ 
    private MapView mapView; 
    private MapController mc; 

    GeoPoint p, p2, p3, p4; 
    List<Overlay> mapOverlays; 
    Drawable drawable, drawable2 , drawable3, drawable4; 
    HelloItemizedOverlay itemizedOverlay, itemizedOverlay2 , itemizedOverlay3, itemizedOverlay4; 

/** Called when the activity is first created. */ 

@Override 

public void onCreate(Bundle savedInstanceState) 

{ 
try{ 
super.onCreate(savedInstanceState); 

setContentView(R.layout.main); 


/* Use the LocationManager class to obtain GPS locations */ 

LocationManager mlocManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE); 

LocationListener mlocListener = new MyLocationListener(); 

mlocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, mlocListener); 
mapView = (MapView) findViewById(R.id.mapView); 

// enable Street view by default 
mapView.setStreetView(true); 

// enable to show Satellite view 
// mapView.setSatellite(true); 

// enable to show Traffic on map 
// mapView.setTraffic(true); 
mapView.setBuiltInZoomControls(true); 

mc = mapView.getController(); 
mapView.setStreetView(true); 
//mapView.setSatellite(true); 
mc.setZoom(12); 
addOverLays(); 
} 
catch(Exception e){ 
    Log.d("eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee",e.getMessage()); 
} 
} 
public void addOverLays(){ 
    String [] coordinates = {"30.084262490272522","31.33625864982605" ,"30.084123015403748", "51.5002" , "-0.1262","31.337149143218994"}; 
    double lat = 30.084262490272522, lat2 = 51.5002,lat3=30.084123015403748; 
    double log = 31.33625864982605, log2 = -0.1262,log3=31.337149143218994; 

    p = new GeoPoint((int) (lat * 1E6), (int) (log * 1E6)); 
    p2 = new GeoPoint((int) (lat2 * 1e6), (int) (log2 * 1e6)); 
    p3=new GeoPoint((int) (lat3 * 1000000), (int) (log3 * 1000000)); 
    mapOverlays = mapView.getOverlays(); 
    drawable = this.getResources().getDrawable(R.drawable.ballon); 
    drawable2 = this.getResources().getDrawable(R.drawable.dotred); 
    drawable3 = this.getResources().getDrawable(R.drawable.icon); 

    itemizedOverlay = new HelloItemizedOverlay(drawable,this); 
    itemizedOverlay2 = new HelloItemizedOverlay(drawable2,this);   
    itemizedOverlay3 = new HelloItemizedOverlay(drawable3,this);  
    OverlayItem overlayitem = new OverlayItem(p, "Cairo", " over1"); 
    OverlayItem over2 = new OverlayItem(p2, "ulm", "over2"); 
    OverlayItem over3 = new OverlayItem(p3, "offff", "over3"); 

    itemizedOverlay.addOverlay(overlayitem); 

    mapOverlays.add(itemizedOverlay); 

    itemizedOverlay2.addOverlay(over2); 
    mapOverlays.add(itemizedOverlay2); 

    itemizedOverlay2.addOverlay(over3); 
    mapOverlays.add(itemizedOverlay3); 
mc.setZoom(17); 
//mc.animateTo(p); 
} 


/* Class My Location Listener */ 



public class MyLocationListener implements LocationListener 

{ 

@Override 

public void onLocationChanged(Location loc) 

{ 





    GeoPoint point = new GeoPoint( (int) (loc.getLatitude() * 1E6), 
      (int) (loc.getLongitude() * 1E6)); 
//DoubletoString(loc.getLatitude()); 

//DoubletoString(loc.getLongitude()); 


String Text = "My current location is: " + 

"Latitud ="+ loc.getLatitude() + 

"Longitud =" + loc.getLongitude(); 


Toast.makeText(getApplicationContext(), 

Text, 

Toast.LENGTH_SHORT).show(); 
mc.animateTo(point); 

} 



private void DoubletoString(double latitude) { 
    // TODO Auto-generated method stub 

} 


public void onProviderDisabled(String provider) 

{ 

Toast.makeText(getApplicationContext(), 

"Gps Disabled", 

Toast.LENGTH_SHORT).show(); 

} 


public void onProviderEnabled(String provider) 

{ 

Toast.makeText(getApplicationContext(), 

"Gps Enabled", 

Toast.LENGTH_SHORT).show(); 

} 


public void onStatusChanged(String provider, int status, Bundle extras) 

{ 


} 
protected boolean isRouteDisplayed() { 
    return false; 
} 

}/* End of Class MyLocationListener */ 


@Override 
protected boolean isRouteDisplayed() { 
    // TODO Auto-generated method stub 
    return false; 
} 


} 


/* End of UseGps Activity*/ 

它強制關閉。這是由於3疊加項目,當我只添加2換句話說,刪除p3是* 1000000.它的工作,但它與它不縮放,當我想放大它顯示力關閉Ie6 * lat與1000000 * lat不一樣嗎?

+0

我不明白這個問題。請清理它。 – 2011-04-24 21:19:36

+0

爲什麼p3 =新的GeoPoint((int)(lat3 * 1000000),(int)(log3 * 1000000));強制關閉!!它出什麼問題了 ?!!它只顯示地圖,但當我按下縮放它沒有響應,並更接近!當我刪除P3!它的工作很好,變焦工作什麼是錯的!緊急我neeed幫助 – lolo 2011-04-24 21:22:33

+3

-1惱人 – 2011-04-24 21:24:34

回答

1

1e6是浮點數,1000000是一個整數。

[[email protected]:~]> cat Test.java 
class Test { 
    public static void main(String[] args) { 
     System.out.println("1e6 = " + 1e6); 
     System.out.println("1000000 = " + 1000000); 
    } 
} 
[[email protected]:~]> javac Test.java && java Test 
1e6 = 1000000.0 
1000000 = 1000000