private void DrawPath(GeoPoint src, GeoPoint dest, int color, MapView mMapView01, Document doc) {

    if (doc != null && doc.getElementsByTagName("GeometryCollection").getLength() > 0) {
      List<Overlay> maliste = mMapView01.getOverlays();
      int pos = maliste.size();
      while (pos > 2) {
        // Codes.mondebug(""+maliste.get(pos-1).getClass());
        mMapView01.getOverlays().remove(pos - 1);

        pos--;
      }
      // String path =
      // doc.getElementsByTagName("GeometryCollection").item(0).getFirstChild().getFirstChild().getNodeName();
      String path =
          doc.getElementsByTagName("GeometryCollection")
              .item(0)
              .getFirstChild()
              .getFirstChild()
              .getFirstChild()
              .getNodeValue();
      // //Log.d("xxx","path="+ path);
      String[] pairs = path.split(" ");
      String[] lngLat = pairs[0].split(","); // lngLat[0]=longitude
      // lngLat[1]=latitude
      // lngLat[2]=height
      // src
      GeoPoint startGP =
          new GeoPoint(
              (int) (Double.parseDouble(lngLat[1]) * 1E6),
              (int) (Double.parseDouble(lngLat[0]) * 1E6));
      mMapView01.getOverlays().add(new MyOverLay(startGP, startGP, 1));
      GeoPoint gp1;
      GeoPoint gp2 = startGP;
      Log.i("", "" + pairs.length);
      for (int i = 1; i < pairs.length; i++) // the last one would be
      // crash
      {
        lngLat = pairs[i].split(",");
        gp1 = gp2;
        // watch out! For GeoPoint, first:latitude, second:longitude
        gp2 =
            new GeoPoint(
                (int) (Double.parseDouble(lngLat[1]) * 1E6),
                (int) (Double.parseDouble(lngLat[0]) * 1E6));
        mMapView01.getOverlays().add(new MyOverLay(gp1, gp2, 2, color));
        // //Log.d("xxx","pair:" + pairs[i]);
      }
      mMapView01.getOverlays().add(new MyOverLay(dest, dest, color)); // use
      // //
      // color
    } else Toast.makeText(getBaseContext(), R.string.txt_error, Toast.LENGTH_LONG).show();
  }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.my_map);
    setResult(RESULT_OK);

    mMap = (MapView) findViewById(R.id.myGmap);
    mMap.setBuiltInZoomControls(true);
    mMap.setSatellite(false);
    mController = mMap.getController();

    Bundle extras = getIntent().getExtras();

    double glat = 0;
    double glon = 0;

    if (extras != null) {
      name = extras.getString("Name");
      glat = extras.getDouble("lat");
      glon = extras.getDouble("lon");
    } else Toast.makeText(this, "Error while getting train position", Toast.LENGTH_LONG).show();

    // Toast.makeText(this, glat + " // " + glon, Toast.LENGTH_LONG).show();

    gpStation = new GeoPoint((int) (glat * 1E6), (int) (glon * 1E6));

    marker = getResources().getDrawable(R.drawable.ic_station_pixelart);
    stationsOverlay = new ItemizedOverlayStation(marker, name, this);
    stationsOverlay.addPoint(gpStation);
    mMap.getOverlays().add(stationsOverlay);

    mController.setCenter(gpStation);
    mController.setZoom(15);

    // adding me= MyLocation(GPS) and also a compass ...

    myLocationOverlay = new FixedMyLocationOverlay(this, mMap);
    myLocationOverlay.enableMyLocation();
    myLocationOverlay.enableCompass();
    mMap.getOverlays().add(myLocationOverlay);

    stationDetailDialog(name, 0);
  }
Exemplo n.º 3
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.googlemaps);
    ActionBar actionBar = getActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
    MapView mapView = (MapView) findViewById(R.id.mapview);
    mapView.setBuiltInZoomControls(true);
    MapController mapController = mapView.getController();
    GeoPoint point = new GeoPoint(42295938, -71297368);
    mapController.setCenter(point);
    mapController.setZoom(15);

    List<Overlay> mapOverlays = mapView.getOverlays();
    Drawable drawable = this.getResources().getDrawable(R.drawable.maparrow);
    MapItemizedOverlay itemizedoverlay = new MapItemizedOverlay(drawable, this);

    OverlayItem overlayitem =
        new OverlayItem(point, "Wellesley Books!", "82 Central St.\nWellesley, MA 02482");

    itemizedoverlay.addOverlay(overlayitem);
    mapOverlays.add(itemizedoverlay);
  }