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
맞음! 그것들은 GeoPoint이고, 내가 작성한 코드는 그것들을 mapView의 좌표 공간에서 점으로 변환합니다. – mharper
공개 무효 연신 (android.graphics.Canvas 캔버스,지도보기지도보기 부울 그림자) { GeoPoint의 새로운 p = ((int)를 (* 30.084262490272522 1E6) (INT) (31.33625864982605 * 1E6)); \t p2 = 새로운 GeoPoint ((int) (29.987107515335083 * 1E6), (int) (31.43912136554718 * 1E6)); 이 바로 또는 !! 그리고이 코드를 어디에 넣을 수 있습니까? – anji
- 1. Application_Start 이후에 경로 추가
- 2. Android GPS에서 경로 추가
- 3. exec-maven-plugin에 추가 경로 추가
- 4. Eclipse 플러그인 빌드 경로 추가
- 5. mingw32의 "경로"에 프로그램 추가
- 6. C# 프로젝트 추가 출력 경로
- 7. MVC 경로 : 경로 시작 부분에 선택적 매개 변수 추가
- 8. ASP.NET 라우팅 - 숫자 인 경우에만 경로 추가?
- 9. 중첩 된 리소스에 컬렉션 경로 추가
- 10. Rails3 메일러의 경로/URL 경로에 변수 추가
- 11. 경로 일치 후 추가 라우트 값 제거
- 12. 은 두 경로 이름을 추가 VC++
- 13. URL에 자동 추가 경로 매개 변수
- 14. MinGW에 여분의 include/lib 경로 추가
- 15. 커널 공간에서 Linux의 경로 추가/제거
- 16. 프로젝트 전반의 추가 라이브러리 경로 - MSVS2008
- 17. PHP : 경로 탐색 경로?
- 18. 복잡한 경로 지정 경로
- 19. 루트 경로 분리 경로
- 20. 경로
- 21. 경로
- 22. 경로
- 23. 루비 레일 경로 및 경로
- 24. VB.NET의 절대 경로 상대 경로
- 25. 다른 컨트롤러의 경로 경로 도우미
- 26. 크롤러, 절대 경로 상대 경로
- 27. qt 타사 헤더 및 라이브러리에 대한 경로 추가
- 28. Eclipse에서 클래스 경로 추가 변수에서 jar를 사용하지 않음
- 29. Python에서 경로 추가 및 호출 외부 프로그램 문제
- 30. Apache rewrite : 모든 요청 경로 앞에 CGI 처리기를 추가 하시겠습니까?
좀 더 일관성있는 전체 형식으로이 코드를 얻을 수있는 모든 기회를? 그것은 읽는 것이 매우 어렵습니다. – mharper
그냥 내게 1 분 – anji