室内地图集:在地图中搜索

时间:2015-12-07 15:53:14

标签: android search indoor-positioning-system atlas

我使用Indoor Atlas进行基于Android的教育项目。 我想将搜索功能实现到我在Indoor Atlas环境中加载的地图中,我怎么能这样做? 例如,我想搜索特定公寓的房间,如何实现此搜索功能?

感谢您的时间

2 个答案:

答案 0 :(得分:0)

您应首先映射该位置。 并做测试路径,使您的地图更精确。 有IndoorAtlas的官方应用程序,所以你可以使用它。

答案 1 :(得分:0)

首先你需要使用indooratlas应用程序映射地板,即IndoorAtlas MapCreator 2.然后你可以使用该应用程序记录坐标,然后你可以保存服务器中的房间/区域的坐标,然后可以获取并指向它搜索后的地图。

/ * gimal.adobe.appsbee.com.gimbaladobe.Indooratlasmap 16/12/16 SUMIT-查克拉博蒂 * / public class IndoorAtlasMap实现了OnMapReadyCallback,GoogleMap.InfoWindowAdapter,GoogleMap.OnInfoWindowClickListener {     private static final String TAG =" IndoorAtlasExample&#34 ;;     私人IndoorAtlasCallBack mIndoorAtlasCallBack;     SupportMapFragment mapFragment;

private static final float HUE_IABLUE = 200.0f;

/* used to decide when bitmap should be downscaled */
private static final int MAX_DIMENSION = 1048;

private GoogleMap mMap; // Might be null if Google Play services APK is not available.
private Marker mMarker;
private Marker mMarkerLoc;
private GroundOverlay mGroundOverlay;
private IALocationManager mIALocationManager;
private IAResourceManager mResourceManager;
private IATask<IAFloorPlan> mFetchFloorPlanTask;
private static LatLng latlongfromlistner;

private Target mLoadTarget;
private boolean mCameraPositionNeedsUpdating;
private ArrayList<ListLatlong> latlong;

LayoutInflater inflater = null;
private TextView textViewTitle;
private RelativeLayout rl_custominfo;

public IndoorAtlasMap(IndoorAtlasCallBack mIndoorAtlasCallBack, LayoutInflater inflater) {
    this.mIndoorAtlasCallBack = mIndoorAtlasCallBack;
    this.inflater = inflater;
}

/**
 * Listener that handles location change events.
 */
private IALocationListener mListener = new IALocationListenerSupport() {

    /**
     * Location changed, move marker and camera position.
     */

    @Override
    public void onLocationChanged(IALocation location) {
        Log.d(TAG, "new location received with coordinates: " + location.getLatitude()
                + "," + location.getLongitude());
        System.out.println("!!!!!!aaa" + location.toString());
          if (mMap == null) {
              // location received before map is initialized, ignoring update here
              return;
          }

          latlongfromlistner = new LatLng(location.getLatitude(), location.getLongitude());

            if (mMarker == null) {
                // first location, add marker
                mMarker = mMap.addMarker(new MarkerOptions().position(latlongfromlistner)
                        .icon(BitmapDescriptorFactory.defaultMarker(HUE_IABLUE)));

            } else {
                // move existing markers position to received location
                mMarker.setPosition(latlongfromlistner);
        }

          // our camera position needs updating if location has significantly changed
          if (mCameraPositionNeedsUpdating) {
              //Create a new CameraPosition
              mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(latlongfromlistner, 19.0f));
              mCameraPositionNeedsUpdating = false;
          }
          mMarker.hideInfoWindow();

    }
    @Override
    public void onStatusChanged(String provider, int status, Bundle extras) {
        switch (status) {
            case IALocationManager.STATUS_CALIBRATION_CHANGED:
                String quality = "unknown";
                switch (extras.getInt("quality")) {
                    case IALocationManager.CALIBRATION_POOR:
                        quality = "Poor";
                        break;
                    case IALocationManager.CALIBRATION_GOOD:
                        quality = "Good";
                        break;
                    case IALocationManager.CALIBRATION_EXCELLENT:
                        quality = "Excellent";
                        break;
                }
                MyLog.d(TAG, "Calibration change. Quality: " + quality);
                break;
            case IALocationManager.STATUS_AVAILABLE:
                MyLog.d(TAG, "onStatusChanged: Available");
                break;
            case IALocationManager.STATUS_LIMITED:
                MyLog.d(TAG, "onStatusChanged: Limited");
                break;
            case IALocationManager.STATUS_OUT_OF_SERVICE:
                MyLog.d(TAG, "onStatusChanged: Out of service");
                break;
            case IALocationManager.STATUS_TEMPORARILY_UNAVAILABLE:
                MyLog.d(TAG, "onStatusChanged: Temporarily unavailable");
        }
        }
};


/**
 * Region listener that when:
 * <ul>
 * <li>region has entered; marks need to move camera and starts
 * loading floor plan bitmap</li>
 * <li>region has existed; clears marker</li>
 * </ul>.
 */
private IARegion.Listener mRegionListener = new IARegion.Listener() {

    @Override
    public void onEnterRegion(IARegion region) {
        System.out.println("!!!!!!aaa enter" + region.toString());
        mIndoorAtlasCallBack.hideLoading();
        if (region.getType() == IARegion.TYPE_UNKNOWN) {
            mIndoorAtlasCallBack.showToast("Moved out of map");
            return;
        }
        // entering new region, mark need to move camera
        mCameraPositionNeedsUpdating = true;
        final String newId = region.getId();
        mIndoorAtlasCallBack.showToast(newId);
        fetchFloorPlan(newId);
    }

    @Override
    public void onExitRegion(IARegion region) {
        System.out.println("!!!!!!aaa exit" + region.toString());
        if (mMarker != null) {
            mMarker.remove();
            mMarker = null;
        }
    }




};

public void onCreatePoints(ArrayList<ListLatlong> latlong) {
    this.latlong = latlong;
    if (null != latlong) {
        for (int i = 0; i < latlong.size(); i++) {
            String title = latlong.get(i).getLoc() != null ? latlong.get(i).getLoc() : "adobe";
            mMarkerLoc = mMap.addMarker(new MarkerOptions().position(latlong.get(i).getLatLng())
                    .title(title)
                    .snippet(String.valueOf(latlong.get(i).getId()))
                    .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED)));
        }
    }
}

/**
 * Sets bitmap of floor plan as ground overlay on Google Maps
 */
private void setupGroundOverlay(IAFloorPlan floorPlan, Bitmap bitmap) {

    if (mGroundOverlay != null) {
        mGroundOverlay.remove();
    }

    if (mMap != null) {
        BitmapDescriptor bitmapDescriptor = BitmapDescriptorFactory.fromBitmap(bitmap);
        IALatLng iaLatLng = floorPlan.getCenter();
        LatLng center = new LatLng(iaLatLng.latitude, iaLatLng.longitude);
        GroundOverlayOptions fpOverlay = new GroundOverlayOptions()
                .image(bitmapDescriptor)
                .position(center, floorPlan.getWidthMeters(), floorPlan.getHeightMeters())
                .bearing(floorPlan.getBearing());

        mGroundOverlay = mMap.addGroundOverlay(fpOverlay);
    }
}

/**
 * Download floor plan using Picasso library.
 */
private void fetchFloorPlanBitmap(final IAFloorPlan floorPlan) {

    final String url = floorPlan.getUrl();
    //saving floor level and floor name
    App.getInstance().getAppPreferences().setFloorId(floorPlan.getFloorLevel());
    App.getInstance().getAppPreferences().setFloorName(floorPlan.getName());
    if (mLoadTarget == null) {
        mLoadTarget = new Target() {

            @Override
            public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
                Log.d(TAG, "onBitmap loaded with dimensions: " + bitmap.getWidth() + "x"
                        + bitmap.getHeight());
                setupGroundOverlay(floorPlan, bitmap);

            }

            @Override
            public void onPrepareLoad(Drawable placeHolderDrawable) {
                // N/A
            }

            @Override
            public void onBitmapFailed(Drawable placeHolderDraweble) {
                mIndoorAtlasCallBack.showToast("Failed to load bitmap");
                mIndoorAtlasCallBack.hideLoading();
            }
        };
    }

    if (null != mIndoorAtlasCallBack.getContext()) {
        RequestCreator request = Picasso.with(mIndoorAtlasCallBack.getContext()).load(url);
        final int bitmapWidth = floorPlan.getBitmapWidth();
        final int bitmapHeight = floorPlan.getBitmapHeight();
        if (bitmapHeight > MAX_DIMENSION) {
            request.resize(0, MAX_DIMENSION);
        } else if (bitmapWidth > MAX_DIMENSION) {
            request.resize(MAX_DIMENSION, 0);
        }

     request.into(mLoadTarget);
    }
    mIndoorAtlasCallBack.onSuccessIndoorMapLoad();
}


/**
 * Fetches floor plan data from IndoorAtlas server.
 */
private void fetchFloorPlan(String id) {

    // if there is already running task, cancel it
    cancelPendingNetworkCalls();

    final IATask<IAFloorPlan> task = mResourceManager.fetchFloorPlanWithId(id);

    task.setCallback(new IAResultCallback<IAFloorPlan>() {

        @Override
        public void onResult(IAResult<IAFloorPlan> result) {

            if (result.isSuccess() && result.getResult() != null) {
                // retrieve bitmap for this floor plan metadata
                fetchFloorPlanBitmap(result.getResult());

            } else {
                // ignore errors if this task was already canceled
                if (!task.isCancelled()) {
                    // do something with error

                    mIndoorAtlasCallBack.showToast("loading floor plan failed: ");
                    // remove current ground overlay
                    if (mGroundOverlay != null) {
                        mGroundOverlay.remove();
                        mGroundOverlay = null;
                    }
                }
            }
        }
    }, Looper.getMainLooper()); // deliver callbacks using main looper

    // keep reference to task so that it can be canceled if needed
    mFetchFloorPlanTask = task;

}

/**
 * Helper method to cancel current task if any.
 */
private void cancelPendingNetworkCalls() {
    if (mFetchFloorPlanTask != null && !mFetchFloorPlanTask.isCancelled()) {
        mFetchFloorPlanTask.cancel();
    }
}

@Override
public void onMapReady(GoogleMap mMap) {
    this.mMap = mMap;
    mMap.setInfoWindowAdapter(this);
    mMap.setOnInfoWindowClickListener(this);
}


public void onDestroyView() {
    mIALocationManager.removeLocationUpdates(mListener);
    mIALocationManager.registerRegionListener(mRegionListener);
    onDestroy();
}

public void onDestroy() {
    mIALocationManager.destroy();
    System.out.println("!!!!!!aaa" + "onDestroyView");
    if (null != mMarker) {
        mMarker.remove();
    }
    if (null != mMarkerLoc) {
        mMarkerLoc.remove();
    }
    mIndoorAtlasCallBack.hideLoading();
}

public void onPause() {
    mIndoorAtlasCallBack.hideLoading();
}


public void onResume() {
    mIALocationManager.requestLocationUpdates(IALocationRequest.create(), mListener);
    mCameraPositionNeedsUpdating = true;
}

public void onIndoorAtlasInit(int map_container) {
    mIndoorAtlasCallBack.showLoading(mIndoorAtlasCallBack.getContext().getResources().getString(R.string.loading_msg));
    FragmentManager fm = mIndoorAtlasCallBack.getChildFragmentManager();
    mapFragment = (SupportMapFragment) fm.findFragmentById(R.id.map_container);
    if (mapFragment == null) {
        mapFragment = SupportMapFragment.newInstance();
        fm.beginTransaction().replace(map_container, mapFragment).commit();
    }
    mapFragment.getMapAsync(this);
    Bundle extras = new Bundle(2);
    extras.putString(IALocationManager.EXTRA_API_KEY,
            App.getInstance().getAppPreferences().getApiKey());
    extras.putString(IALocationManager.EXTRA_API_SECRET,
            App.getInstance().getAppPreferences().getSecretkey());

    mIALocationManager = IALocationManager.create(mIndoorAtlasCallBack.getContext(), extras);

    final String floorPlanId = App.getInstance().getAppPreferences().getFloorPlanId();
    if (!TextUtils.isEmpty(floorPlanId)) {
        final IALocation location = IALocation.from(IARegion.floorPlan(floorPlanId));
        mIALocationManager.setLocation(location);
    }

    mResourceManager = IAResourceManager.create(mIndoorAtlasCallBack.getContext(), extras);

    mIALocationManager.requestLocationUpdates(IALocationRequest.create(), mListener);
    mIALocationManager.registerRegionListener(mRegionListener);
}

@Override
public View getInfoWindow(final Marker marker) {
    View v = inflater.inflate(R.layout.mapinfowindow, null);
    if (marker != null && (marker.getTitle() != null && marker.getTitle().length() > 0)) {
        MyLog.sout("!!!!oninfowindow", marker.getSnippet());
        textViewTitle = (TextView) v.findViewById(R.id.textViewTitle);
        rl_custominfo = (RelativeLayout) v.findViewById(R.id.rl_custominfo);
        textViewTitle.setText(marker.getTitle());
        textViewTitle.setVisibility(View.VISIBLE);
        rl_custominfo.setVisibility(View.VISIBLE);
    } else{
        return null;
    }
    return (v);
}

@Override
public View getInfoContents(Marker marker) {
    return null;
}


@Override
public void onInfoWindowClick(Marker marker) {
    MyLog.sout("!!!!oninfo", marker.getSnippet());
   LatLng latlng = marker.getPosition();
    Double distance = CalculateDistancex.CalculationByDistance(latlng,latlongfromlistner) ;
    distance = distance*100;
    distance = Double.valueOf(Math.round(distance));
    distance = distance /100;
    if(null !=marker) {
        mIndoorAtlasCallBack.onClickFromInfoWindow(marker.getSnippet(), distance);
    }
}

}