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=29.987091422080994;
double log = 31.33625864982605, log2 = -0.1262,log3=31.43909454345703;
p = new GeoPoint((int) (lat * 1E6), (int) (log * 1E6));
p2 = new GeoPoint((int) (lat2 * 1e6), (int) (log2 * 1e6));
p3=new GeoPoint((int) (lat3 * 1e6), (int) (log3 * 1e6));
mapOverlays = mapView.getOverlays();
drawable = this.getResources().getDrawable(R.drawable.ballon);
drawable2 = this.getResources().getDrawable(R.drawable.ballon);
drawable3 = this.getResources().getDrawable(R.drawable.ballon);
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);
itemizedOverlay3.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;
}
}
// i want to add path between this two overlay items
加入路徑
回答
我認爲你想知道的是:如果你有帶有兩個GeoPoints,你怎麼有重疊繪製兩點之間的直線覆蓋?
在您的覆蓋子類的draw()
方法,你會做類似如下:
@Override
public void draw(android.graphics.Canvas canvas, MapView mapView, boolean shadow)
{
GeoPoint point1, point2;
// Let's assume you've assigned values to these two GeoPoints now.
Projection projection = mapView.getProjection();
Point startingPoint = projection.toPixels(point1, null);
Point endingPoint = projection.toPixels(point2, null);
// Create the path containing the line between the two points.
Path path = new Path();
path.moveTo(startingPoint.x, startingPoint.y);
path.lineTo(endingPoint.x, endingPoint.y);
// Setup the paint. You'd probably do this outside of the draw() method to be more efficient.
Paint paint = new Paint();
paint.setStyle(Paint.Style.STROKE);
// Can set other paint characteristics, such as width, anti-alias, color, etc....
// Draw the path!
canvas.drawPath(path, paint);
}
和點1,點2是我的位置或我想要畫的線和點。對 ! – anji 2011-04-27 22:35:04
正確!他們是GeoPoints,我寫的代碼將它們轉換成mapView座標空間中的點。 – mharper 2011-04-27 22:45:36
public void draw(android.graphics.Canvas canvas,MapView mapView,boolean shadow) p = new GeoPoint((int)(30.084262490272522 * 1E6),(int)(31.33625864982605 * 1E6)); \t P2 =新的GeoPoint((int)的(29.987107515335083 * 1E6),(INT)(31.43912136554718 * 1E6)); 是這個權利或!和我在哪裏可以把這個方法放在我的代碼中? – anji 2011-04-27 23:04:38
- 1. 拆分路徑+加入路徑功能
- 2. 加入路徑來RStudio的路徑
- 3. HQL加入 - 加入的路徑!休眠
- 4. ManyToMany HQL加入 - 預計加入路徑
- 5. POSIX兼容路徑加入
- 6. org.hibernate.hql.internal.ast.QuerySyntaxException:路徑預期加入
- 7. 休眠路徑加入,但路徑設置
- 8. 加入錯誤的路徑預期
- 9. 加入路徑時出現Segfault
- 10. 解析使用Ant和加入路徑
- 11. Python如何加入跨平臺路徑
- 12. 在url路徑中加入url參數
- 13. HQL錯誤:預計加入的路徑
- 14. 在mysql中優化多路徑加入
- 15. 加入Java中的遠程路徑
- 16. QuerySyntaxException:路徑預期的加入
- 17. 指南針,添加導入路徑
- 18. HQL錯誤 - 預計加入的路徑
- 19. 加入的路徑! Nhibernate錯誤
- 20. Hibernate HQL「加入的路徑!」 @ManyToOne關係
- 21. 將路徑附加到路徑
- 22. 添加路徑到Erlang搜索路徑?
- 23. 配置路徑加載器路徑
- 24. AngularJS - templateUrl路徑附加到href路徑
- 25. JPA查詢加入錯誤:org.hibernate.hql.internal.ast.QuerySyntaxException:路徑預期的加入
- 26. HQL預期加入路徑(加入同一張表時)
- 27. emacs加載路徑
- 28. 添加路徑AC_CHECK_LIB
- 29. 加密加密路徑
- 30. 當通過管道傳遞路徑時Powershell的加入路徑錯誤
任何機會,你可以得到這個代碼到一個更加一致的整體格式?按原樣閱讀是非常具有挑戰性的。 – mharper 2011-04-27 21:41:53
只給我1分 – anji 2011-04-27 21:44:02