Beispiel #1
0
  public void postRequestHandler(String result) {

    aButton.setEnabled(true);

    JSONObject json_obj;

    try {

      json_obj = new JSONObject(result);

      String slat = json_obj.getString("latitude");
      String slong = json_obj.getString("longitude");
      String countryname = json_obj.getString("country_name");
      String city = json_obj.getString("city");
      String region = json_obj.getString("region");

      double lat = Double.parseDouble(slat);
      double lon = Double.parseDouble(slong);

      GeoPoint gp = getPoint(lat, lon);
      mapView.getController().setZoom(9);
      mapView.getController().animateTo(gp);

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

      OverlayItem overlayitem = new OverlayItem(gp, ipaddress, ipaddress);

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

      TextView textView = (TextView) findViewById(R.id.display);
      textView.setText(
          "Longitude = "
              + slat
              + " \nLongitude = "
              + slong
              + " \nCity = "
              + city
              + " \nRegion = "
              + region
              + " \nCountry = "
              + countryname);
      textView.setHorizontalScrollBarEnabled(true);

      Toast toast = Toast.makeText(getApplicationContext(), "Request has completed succesfully", 3);
      toast.show();

    } catch (JSONException e) {
      Toast toast =
          Toast.makeText(
              getApplicationContext(), "Unable to process request...please try again", 10);
      toast.show();
    }
  }
Beispiel #2
0
  public void drawPlace() {
    // Prepare overlays: Center overlay and Details overlay
    Drawable marker = getResources().getDrawable(R.drawable.marker);
    Drawable centermarker = getResources().getDrawable(R.drawable.centermarker);
    centermarker.setBounds(0, 0, marker.getIntrinsicWidth(), marker.getIntrinsicHeight());
    centerOverlay = new SitesOverlay(centermarker);
    Drawable detailmarker = getResources().getDrawable(R.drawable.star);
    detailmarker.setBounds(0, 0, marker.getIntrinsicWidth(), marker.getIntrinsicHeight());
    detailOverlay = new SitesOverlay(detailmarker);

    // Add remain overlays into map
    centerOverlay.addItem(
        new OverlayItem(
            getPoint(curLAT, curLNG), "My Location", "My Location\n" + curLAT + " - " + curLNG));
    centerOverlay.completeToPopulate();

    // add user location
    map.getOverlays().add(centerOverlay);
    map.getOverlays().add(me);

    if (respectLocation != null) {
      // Draw position to map
      double detailLAT = respectLocation.getLat();
      double detailLNG = respectLocation.getLng();
      String address = "";
      address +=
          respectLocation.getHouse_number()
              + ", "
              + respectLocation.getStreet()
              + ", "
              + respectLocation.getWard()
              + ", "
              + respectLocation.getDistrict()
              + ", "
              + respectLocation.getCity();
      String des =
          respectLocation.getName() + "\n" + address + "\n" + detailLAT + " - " + detailLNG;
      detailOverlay.addItem(
          new OverlayItem(getPoint(detailLAT, detailLNG), respectLocation.getName(), des));
      detailOverlay.completeToPopulate();
      map.getOverlays().add(detailOverlay);

      // Get route direction and list route point to draw map
      fromLat = fromLocation.getLat();
      fromLng = fromLocation.getLng();
      try {
        ms.getRoute(respectLocation, fromLat, fromLng, "en");
        listRoutePoint = ms.getListPathPoint();
      } catch (Exception e) {
      }
      directionEN = ms.getDirection();
      statusDirection = ms.getStatusDirection();

      // can not find the direction, listRoutePoint == null
      if (!statusDirection.equals("OK")) {
        detailOverlay.addItem(
            new OverlayItem(getPoint(detailLAT, detailLNG), respectLocation.getName(), des));
        detailOverlay.completeToPopulate();
        map.getOverlays().add(detailOverlay);
      }
    }
  }
 public void setPlaces(List<JSONObject> newPlaces) {
   places = newPlaces;
   overlay.update();
   ListView list = (ListView) findViewById(R.id.placeList);
   ((PlaceAdapter) list.getAdapter()).setPlaces(places);
 }