コード例 #1
0
 @Override
 public View getView(int position, View convertView, ViewGroup parent) {
   // TODO Auto-generated method stub
   ViewHolder viewHolder;
   if (convertView == null) {
     convertView = inflater.inflate(R.layout.item_selectlocation, null);
     viewHolder = new ViewHolder();
     viewHolder.title = (TextView) convertView.findViewById(R.id.selectlocation_item_title);
     viewHolder.detail = (TextView) convertView.findViewById(R.id.selectlocation_item_detail);
     viewHolder.icon = (ImageView) convertView.findViewById(R.id.selectlocation_item_icon);
     convertView.setTag(viewHolder);
   } else {
     viewHolder = (ViewHolder) convertView.getTag();
   }
   LocationPoint point = locationList.get(position);
   if (position == 0) {
     viewHolder.title.setText("[ 位置 ]");
   } else {
     viewHolder.title.setText(point.getTitle());
   }
   viewHolder.detail.setText(point.getDetail());
   if (point.isSelected) {
     viewHolder.icon.setVisibility(View.VISIBLE);
   } else {
     viewHolder.icon.setVisibility(View.GONE);
   }
   return convertView;
 }
コード例 #2
0
 /**
  * works out the total distance traveled along the walk.
  *
  * @return the running total of km traveled.
  */
 public double getDistance() {
   double total = 0;
   for (int i = 0; i < path.size() - 1; i++) {
     total += LocationPoint.distBetween(path.get(i), path.get(i + 1));
   }
   return total;
 }
コード例 #3
0
  private String computeNearbyLocation(LocationPoint measurementPt) {
    Double dist = 999.99;
    String nearbyLoc = "Cannot be localized!";
    String strToast = "";
    for (LocationPoint ref : references) {
      Double d = ref.distanceFrom(measurementPt);

      if (Double.compare(d, dist) <= 0) {
        dist = d;
        nearbyLoc = ref.name + " (Dist: " + String.format("%.2f", d) + ")";
      }

      strToast = strToast + ref.name + " (Dist: " + String.format("%.2f", d) + ")" + "\n";
    }
    Toast.makeText(LocalizationActivity.this, strToast, Toast.LENGTH_SHORT).show();
    return nearbyLoc;
  }
コード例 #4
0
 @Override
 public void onClick(View v) {
   switch (v.getId()) {
     case R.id.selectlocation_back:
       SelectLocationActivity.this.setResult(RESULT_CANCELED);
       SelectLocationActivity.this.finish();
       break;
     case R.id.selectlocation_ok:
       LocationPoint locationPoint = locationList.get(currentLocation);
       Intent intent = new Intent();
       intent.putExtra("location_address", locationPoint.detail);
       intent.putExtra("location_latitude", locationPoint.getLatLng().latitude);
       intent.putExtra("location_longitude", locationPoint.getLatLng().longitude);
       SelectLocationActivity.this.setResult(RESULT_OK, intent);
       if (client != null && !client.isStarted()) {
         client.stop();
       }
       SelectLocationActivity.this.finish();
       break;
     default:
       break;
   }
 }
コード例 #5
0
 @Override
 public void onGetReverseGeoCodeResult(ReverseGeoCodeResult result) {
   showWaiting(false);
   if (result != null) {
     if (result.getPoiList() == null) {
       showToast("获取位置信息失败,请重新获取");
       SelectLocationActivity.this.setResult(RESULT_CANCELED);
       SelectLocationActivity.this.finish();
       return;
     }
     locationList.clear();
     LocationPoint firstPoint =
         new LocationPoint("[ 位置 ]", result.getAddress(), result.getLocation());
     firstPoint.setSelected(true);
     locationList.add(firstPoint);
     List<PoiInfo> allAddrList = result.getPoiList();
     for (PoiInfo info : allAddrList) {
       LocationPoint point = new LocationPoint(info.name, info.address, info.location);
       point.setSelected(false);
       locationList.add(point);
       System.out.println("地址:" + info.name + ":" + info.address);
     }
     currentLocation = 0;
     adapter.notifyDataSetChanged();
     ok.setEnabled(true);
   } else {
     System.out.println("---->null--------------------");
     if (client != null && !client.isStarted()) {
       ToastUtil.show(SelectLocationActivity.this, "定位不成功,正在自动重新定位");
       client.start();
     } else {
       showToast("获取位置信息失败,请重新获取");
       SelectLocationActivity.this.setResult(RESULT_CANCELED);
       SelectLocationActivity.this.finish();
     }
   }
 }