2015-08-24 45 views
1

我已經創建了一個應該跟蹤POI的小型Android應用程序。我瀏覽一條路線,並在路線的開始處放置10個可追蹤的POI,並在整個路線上放置許多其他可追蹤的POI。當我在可追蹤的POI上添加註釋時,可以看到它們已創建。我想用SKPOITrackerManager跟蹤它們。但是這些POI都沒有被跟蹤。SKPOITrackerManager不檢測任何POI

我實施了SKPOITrackerListeneronUpdatePOIsinRadius()被稱爲前兩次未添加任何POIs。第三次被叫(在我開始的應用程序後約2分鐘),它增加了許多POI。但onReceivedPOIs()找不到POI。它只被調用一次。並且List<SKDetectedPOI>僅具有尺寸1,其具有ID等於-1的檢測到的POI。

這是我的完整代碼,包含兩個Activites。

MainActivity:

package com.example.michi.mapapplication; 

import android.app.Activity; 
import android.content.Context; 
import android.content.Intent; 
import android.os.Environment; 
import android.os.StatFs; 
import android.support.v7.app.AppCompatActivity; 
import android.os.Bundle; 
import android.util.Log; 
import android.view.Menu; 
import android.view.MenuItem; 
import android.widget.Toast; 

import com.skobbler.ngx.SKDeveloperKeyException; 
import com.skobbler.ngx.SKMaps; 
import com.skobbler.ngx.SKMapsInitSettings; 
import com.skobbler.ngx.SKPrepareMapTextureListener; 
import com.skobbler.ngx.SKPrepareMapTextureThread; 
import com.skobbler.ngx.map.SKMapViewStyle; 
import com.skobbler.ngx.navigation.SKAdvisorSettings; 
import com.skobbler.ngx.util.SKLogging; 
import com.skobbler.ngx.versioning.SKMapUpdateListener; 
import com.skobbler.ngx.versioning.SKVersioningManager; 

import java.lang.reflect.InvocationTargetException; 
import java.lang.reflect.Method; 

public class MainActivity extends AppCompatActivity implements SKPrepareMapTextureListener{ 

    private final static String TAG = "MainActivity"; 
    private String mapResourcesDirPath = ""; 

    public static final long KILO = 1024; 

    public static final long MEGA = KILO * KILO; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     String applicationPath = chooseStoragePath(this); 
     mapResourcesDirPath = applicationPath + "/" + "SKMaps/"; 
     new SKPrepareMapTextureThread(this, mapResourcesDirPath, "SKMaps.zip", this).start(); 
     if (initializeLibrary(this)) { 
      finish(); 
      startActivity(new Intent(this, MapActivity.class)); 
     } 
    } 

    private boolean initializeLibrary(final Activity context) { 
     SKLogging.enableLogs(true); 
     SKMapsInitSettings initMapSettings = new SKMapsInitSettings(); 
     initMapSettings.setMapResourcesPaths(mapResourcesDirPath, 
       new SKMapViewStyle(mapResourcesDirPath + "daystyle/", "daystyle.json")); 
     final SKAdvisorSettings advisorSettings = initMapSettings.getAdvisorSettings(); 
     advisorSettings.setAdvisorConfigPath(mapResourcesDirPath +"/Advisor"); 
     advisorSettings.setResourcePath(mapResourcesDirPath +"/Advisor/Languages"); 
     advisorSettings.setLanguage(SKAdvisorSettings.SKAdvisorLanguage.LANGUAGE_DE); 
     advisorSettings.setAdvisorVoice("en"); 
     initMapSettings.setAdvisorSettings(advisorSettings); 
     try { 
      SKMaps.getInstance().initializeSKMaps(context, initMapSettings); 
      return true; 
     }catch (SKDeveloperKeyException exception){ 
      exception.printStackTrace(); 
      return false; 
     } 
    } 

    public static String chooseStoragePath(Context context) { 
     if (getAvailableMemorySize(Environment.getDataDirectory().getPath()) >= 50 * MEGA) { 
      if (context != null && context.getFilesDir() != null) { 
       return context.getFilesDir().getPath(); 
      } 
     } else { 
      if ((context != null) && (context.getExternalFilesDir(null) != null)) { 
       if (getAvailableMemorySize(context.getExternalFilesDir(null).toString()) >= 50 * MEGA) { 
        return context.getExternalFilesDir(null).toString(); 
       } 
      } 
     } 

     SKLogging.writeLog(TAG, "There is not enough memory on any storage, but return internal memory", 
       SKLogging.LOG_DEBUG); 

     if (context != null && context.getFilesDir() != null) { 
      return context.getFilesDir().getPath(); 
     } else { 
      if ((context != null) && (context.getExternalFilesDir(null) != null)) { 
       return context.getExternalFilesDir(null).toString(); 
      } else { 
       return null; 
      } 
     } 
    } 

    public static long getAvailableMemorySize(String path) { 
     StatFs statFs = null; 
     try { 
      statFs = new StatFs(path); 
     } catch (IllegalArgumentException ex) { 
      SKLogging.writeLog("SplashActivity", "Exception when creating StatF ; message = " + ex, 
        SKLogging.LOG_DEBUG); 
     } 
     if (statFs != null) { 
      Method getAvailableBytesMethod = null; 
      try { 
       getAvailableBytesMethod = statFs.getClass().getMethod("getAvailableBytes"); 
      } catch (NoSuchMethodException e) { 
       SKLogging.writeLog(TAG, "Exception at getAvailableMemorySize method = " + e.getMessage(), 
         SKLogging.LOG_DEBUG); 
      } 

      if (getAvailableBytesMethod != null) { 
       try { 
        SKLogging.writeLog(TAG, "Using new API for getAvailableMemorySize method !!!", SKLogging.LOG_DEBUG); 
        return (Long) getAvailableBytesMethod.invoke(statFs); 
       } catch (IllegalAccessException e) { 
        return (long) statFs.getAvailableBlocks() * (long) statFs.getBlockSize(); 
       } catch (InvocationTargetException e) { 
        return (long) statFs.getAvailableBlocks() * (long) statFs.getBlockSize(); 
       } 
      } else { 
       return (long) statFs.getAvailableBlocks() * (long) statFs.getBlockSize(); 
      } 
     } else { 
      return 0; 
     } 
    } 

    @Override 
    public void onMapTexturesPrepared(boolean b) { 
     initializeLibrary(this); 
    } 
} 

MapActivity:

package com.example.michi.mapapplication; 

import android.graphics.Color; 
import android.os.Bundle; 
import android.support.v7.app.AppCompatActivity; 
import android.util.Log; 
import android.view.View; 
import android.widget.Toast; 

import com.skobbler.ngx.SKCoordinate; 
import com.skobbler.ngx.map.SKAnimationSettings; 
import com.skobbler.ngx.map.SKAnnotation; 
import com.skobbler.ngx.map.SKCalloutView; 
import com.skobbler.ngx.map.SKCoordinateRegion; 
import com.skobbler.ngx.map.SKMapCustomPOI; 
import com.skobbler.ngx.map.SKMapPOI; 
import com.skobbler.ngx.map.SKMapSettings; 
import com.skobbler.ngx.map.SKMapSurfaceListener; 
import com.skobbler.ngx.map.SKMapSurfaceView; 
import com.skobbler.ngx.map.SKMapViewHolder; 
import com.skobbler.ngx.map.SKPOICluster; 
import com.skobbler.ngx.map.SKScreenPoint; 
import com.skobbler.ngx.navigation.SKNavigationListener; 
import com.skobbler.ngx.navigation.SKNavigationManager; 
import com.skobbler.ngx.navigation.SKNavigationSettings; 
import com.skobbler.ngx.navigation.SKNavigationState; 
import com.skobbler.ngx.poitracker.SKDetectedPOI; 
import com.skobbler.ngx.poitracker.SKPOITrackerListener; 
import com.skobbler.ngx.poitracker.SKPOITrackerManager; 
import com.skobbler.ngx.poitracker.SKTrackablePOI; 
import com.skobbler.ngx.poitracker.SKTrackablePOIRule; 
import com.skobbler.ngx.poitracker.SKTrackablePOIType; 
import com.skobbler.ngx.routing.SKRouteInfo; 
import com.skobbler.ngx.routing.SKRouteJsonAnswer; 
import com.skobbler.ngx.routing.SKRouteListener; 
import com.skobbler.ngx.routing.SKRouteManager; 
import com.skobbler.ngx.routing.SKRouteSettings; 

import java.util.ArrayList; 
import java.util.HashMap; 
import java.util.List; 

import butterknife.Bind; 
import butterknife.ButterKnife; 

import static com.skobbler.ngx.map.SKMapSettings.SKMapDisplayMode.MODE_2D; 
import static com.skobbler.ngx.map.SKMapSettings.SKMapDisplayMode.MODE_3D; 

public class MapActivity extends AppCompatActivity implements SKMapSurfaceListener, SKRouteListener, SKNavigationListener, SKPOITrackerListener { 

    public static final double SOURCE_LONGITUDE = 11.5; 
    public static final double SOURCE_LATITUDE = 48.12; 
    public static final double DEST_LONGITUDE = 11.5; 
    public static final double DEST_LATITUDE = 51.12; 

    private SKNavigationManager navigationManager; 
    private HashMap<Integer, SKTrackablePOI> trackablePOIs; 
    private SKPOITrackerManager poiTrackerManager; 

    protected SKMapSurfaceView mapView; 
    @Bind(R.id.view_group_map) 
    protected SKMapViewHolder mapHolder; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_map); 
     ButterKnife.bind(this); 
     mapHolder.setMapSurfaceListener(this); 
    } 

    @Override 
    protected void onPause() { 
     super.onPause(); 
     mapHolder.onPause(); 
    } 

    @Override 
    protected void onResume() { 
     super.onResume(); 
     mapHolder.onResume(); 
    } 

    @Override 
    public void onActionPan() {} 

    @Override 
    public void onActionZoom() { } 

    @Override 
    public void onSurfaceCreated(SKMapViewHolder skMapViewHolder) { 
     mapView = mapHolder.getMapSurfaceView(); 
     mapView.centerMapOnPosition(new SKCoordinate(11.5, 48.12)); 
     launchRouteCalculation(); 
    } 

    @Override 
    public void onMapRegionChanged(SKCoordinateRegion skCoordinateRegion) { 
     mapView.getMapSettings().setFollowerMode(SKMapSettings.SKMapFollowerMode.NONE); 
     final SKCalloutView mapPopup = mapHolder.getCalloutView(); 
     mapPopup.setTitle("Fortsetzen").setVisibility(View.VISIBLE); 
     mapPopup.setViewColor(Color.argb(255, 200, 200, 255)); 
     mapPopup.setOnLeftImageClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View view) { 
       Toast.makeText(MapActivity.this, "Left image clicked", Toast.LENGTH_SHORT).show(); 
       mapView.getMapSettings().setFollowerMode(SKMapSettings.SKMapFollowerMode.NAVIGATION); 
       mapPopup.setVisibility(View.GONE); 
      } 
     }); 
     mapPopup.showAtLocation(new SKCoordinate(23.56, 46.77), true); 
    } 

    @Override 
    public void onMapRegionChangeStarted(SKCoordinateRegion skCoordinateRegion) {} 
    @Override 
    public void onMapRegionChangeEnded(SKCoordinateRegion skCoordinateRegion) {} 
    @Override 
    public void onDoubleTap(SKScreenPoint skScreenPoint) {} 
    @Override 
    public void onSingleTap(SKScreenPoint skScreenPoint) {} 
    @Override 
    public void onRotateMap() {} 
    @Override 
    public void onLongPress(SKScreenPoint skScreenPoint) {} 
    @Override 
    public void onInternetConnectionNeeded() {} 
    @Override 
    public void onMapActionDown(SKScreenPoint skScreenPoint) {} 
    @Override 
    public void onMapActionUp(SKScreenPoint skScreenPoint) {} 
    @Override 
    public void onPOIClusterSelected(SKPOICluster skpoiCluster) {} 
    @Override 
    public void onMapPOISelected(SKMapPOI skMapPOI) {} 
    @Override 
    public void onAnnotationSelected(SKAnnotation skAnnotation) { 
    } 
    @Override 
    public void onCustomPOISelected(SKMapCustomPOI skMapCustomPOI) {} 
    @Override 
    public void onCompassSelected() { 
    } 
    @Override 
    public void onCurrentPositionSelected() {} 
    @Override 
    public void onObjectSelected(int i) {} 
    @Override 
    public void onInternationalisationCalled(int i) {} 
    @Override 
    public void onDebugInfo(double v, float v1, double v2) { } 
    @Override 
    public void onBoundingBoxImageRendered(int i) {} 
    @Override 
    public void onGLInitializationError(String s) {} 
    private void launchRouteCalculation() { 
     SKRouteSettings route = new SKRouteSettings(); 
     route.setStartCoordinate(new SKCoordinate(SOURCE_LONGITUDE, SOURCE_LATITUDE)); 
     route.setDestinationCoordinate(new SKCoordinate(DEST_LONGITUDE, DEST_LATITUDE)); 
     route.setNoOfRoutes(1); 
     route.setRouteMode(SKRouteSettings.SKRouteMode.CAR_FASTEST); 
     route.setRouteExposed(true); 
     SKRouteManager.getInstance().setRouteListener(this); 
     SKRouteManager.getInstance().calculateRoute(route); 
    } 
    @Override 
    public void onRouteCalculationCompleted(SKRouteInfo skRouteInfo) {} 
    @Override 
    public void onRouteCalculationFailed(SKRoutingErrorCode skRoutingErrorCode) {} 
    @Override 
    public void onAllRoutesCompleted() { 
     SKNavigationSettings navigationSettings = new SKNavigationSettings(); 
     navigationSettings.setNavigationType(SKNavigationSettings.SKNavigationType.SIMULATION); 

     navigationManager = SKNavigationManager.getInstance(); 
     navigationManager.setMapView(mapView); 
     navigationManager.setNavigationListener(this); 
     navigationManager.startNavigation(navigationSettings); 

     initTrackablePOIs(); 
     try { 
      Thread.sleep(2000); 
     } catch (InterruptedException e) { 
      e.printStackTrace(); 
     } 
     startPOITracking(); 
    } 


    private void initTrackablePOIs() { 
     Log.w(getClass().getName(), "initTrackablePOIs(): "); 
     trackablePOIs = new HashMap<Integer, SKTrackablePOI>(); 
     initOnlySomePOIs(); 
     int i = 0; 
     double longitude, latitude; 
     for (double d = 0; d < 1; d+= 0.01) { 
      longitude = SOURCE_LONGITUDE + d * (DEST_LONGITUDE - SOURCE_LONGITUDE); 
      latitude = SOURCE_LATITUDE + d * (DEST_LATITUDE - SOURCE_LATITUDE); 
      trackablePOIs.put(i, new SKTrackablePOI(i, 1, longitude, latitude, -1, "STREET_NAME " + i)); 
      SKAnnotation skAnnotation = new SKAnnotation(64000 + i); 
      skAnnotation.setAnnotationType(SKAnnotation.SK_ANNOTATION_TYPE_MARKER); 
      skAnnotation.setLocation(new SKCoordinate(longitude, latitude)); 
      mapView.addAnnotation(skAnnotation, SKAnimationSettings.ANIMATION_PIN_DROP); 
      i++; 
     } 
    } 

    private void initOnlySomePOIs() { 
     double longitude, latitude; 

     longitude = SOURCE_LONGITUDE + 0.001; 
     latitude = SOURCE_LATITUDE + 0.001; 
     trackablePOIs.put(101, new SKTrackablePOI(101, 1, longitude, latitude, -1, "STREET_NAME 101")); 
     SKAnnotation skAnnotation1 = new SKAnnotation(101); 
     skAnnotation1.setAnnotationType(SKAnnotation.SK_ANNOTATION_TYPE_MARKER); 
     skAnnotation1.setLocation(new SKCoordinate(longitude, latitude)); 
     mapView.addAnnotation(skAnnotation1, SKAnimationSettings.ANIMATION_PIN_DROP); 

     longitude = SOURCE_LONGITUDE + 0.001; 
     latitude = SOURCE_LATITUDE - 0.001; 
     trackablePOIs.put(102, new SKTrackablePOI(102, 1, longitude, latitude, -1, "STREET_NAME 102")); 
     SKAnnotation skAnnotation2 = new SKAnnotation(102); 
     skAnnotation2.setAnnotationType(SKAnnotation.SK_ANNOTATION_TYPE_MARKER); 
     skAnnotation2.setLocation(new SKCoordinate(longitude, latitude)); 
     mapView.addAnnotation(skAnnotation2, SKAnimationSettings.ANIMATION_PIN_DROP); 

     longitude = SOURCE_LONGITUDE - 0.001; 
     latitude = SOURCE_LATITUDE + 0.001; 
     trackablePOIs.put(103, new SKTrackablePOI(103, 1, longitude, latitude, -1, "STREET_NAME 103")); 
     SKAnnotation skAnnotation3 = new SKAnnotation(103); 
     skAnnotation3.setAnnotationType(SKAnnotation.SK_ANNOTATION_TYPE_MARKER); 
     skAnnotation3.setLocation(new SKCoordinate(longitude, latitude)); 
     mapView.addAnnotation(skAnnotation3, SKAnimationSettings.ANIMATION_PIN_DROP); 

     longitude = SOURCE_LONGITUDE - 0.001; 
     latitude = SOURCE_LATITUDE - 0.001; 
     trackablePOIs.put(104, new SKTrackablePOI(104, 1, longitude, latitude, -1, "STREET_NAME 104")); 
     SKAnnotation skAnnotation4 = new SKAnnotation(104); 
     skAnnotation4.setAnnotationType(SKAnnotation.SK_ANNOTATION_TYPE_MARKER); 
     skAnnotation4.setLocation(new SKCoordinate(longitude, latitude)); 
     mapView.addAnnotation(skAnnotation4, SKAnimationSettings.ANIMATION_PIN_DROP); 

     longitude = SOURCE_LONGITUDE + 0.002; 
     latitude = SOURCE_LATITUDE + 0.002; 
     trackablePOIs.put(105, new SKTrackablePOI(105, 105, longitude, latitude, -1, "STREET_NAME 105")); 
     SKAnnotation skAnnotation5 = new SKAnnotation(105); 
     skAnnotation5.setAnnotationType(SKAnnotation.SK_ANNOTATION_TYPE_MARKER); 
     skAnnotation5.setLocation(new SKCoordinate(longitude, latitude)); 
     mapView.addAnnotation(skAnnotation5, SKAnimationSettings.ANIMATION_PIN_DROP); 

     longitude = SOURCE_LONGITUDE + 0.002; 
     latitude = SOURCE_LATITUDE - 0.002; 
     trackablePOIs.put(106, new SKTrackablePOI(106, 1, longitude, latitude, -1, "STREET_NAME 106")); 
     SKAnnotation skAnnotation6 = new SKAnnotation(106); 
     skAnnotation6.setAnnotationType(SKAnnotation.SK_ANNOTATION_TYPE_MARKER); 
     skAnnotation6.setLocation(new SKCoordinate(longitude, latitude)); 
     mapView.addAnnotation(skAnnotation6, SKAnimationSettings.ANIMATION_PIN_DROP); 

     longitude = SOURCE_LONGITUDE - 0.002; 
     latitude = SOURCE_LATITUDE + 0.002; 
     trackablePOIs.put(107, new SKTrackablePOI(107, 1, longitude, latitude, -1, "STREET_NAME 107")); 
     SKAnnotation skAnnotation7 = new SKAnnotation(107); 
     skAnnotation7.setAnnotationType(SKAnnotation.SK_ANNOTATION_TYPE_MARKER); 
     skAnnotation7.setLocation(new SKCoordinate(longitude, latitude)); 
     mapView.addAnnotation(skAnnotation7, SKAnimationSettings.ANIMATION_PIN_DROP); 

     longitude = SOURCE_LONGITUDE - 0.001; 
     latitude = SOURCE_LATITUDE - 0.001; 
     trackablePOIs.put(108, new SKTrackablePOI(108, 1, longitude, latitude, -1, "STREET_NAME 108")); 
     SKAnnotation skAnnotation8 = new SKAnnotation(108); 
     skAnnotation8.setAnnotationType(SKAnnotation.SK_ANNOTATION_TYPE_MARKER); 
     skAnnotation8.setLocation(new SKCoordinate(longitude, latitude)); 
     mapView.addAnnotation(skAnnotation8, SKAnimationSettings.ANIMATION_PIN_DROP); 

     longitude = 9.767972; 
     latitude = 52.378958; 
     trackablePOIs.put(109, new SKTrackablePOI(109, 1, longitude, latitude, -1, "STREET_NAME 109")); 
     SKAnnotation skAnnotation9 = new SKAnnotation(109); 
     skAnnotation9.setAnnotationType(SKAnnotation.SK_ANNOTATION_TYPE_MARKER); 
     skAnnotation9.setLocation(new SKCoordinate(longitude, latitude)); 
     mapView.addAnnotation(skAnnotation9, SKAnimationSettings.ANIMATION_PIN_DROP); 
    } 

    private void startPOITracking() { 
     SKTrackablePOIRule rule = new SKTrackablePOIRule(); 
     rule.setAerialDistance(5000); // this would be our main constraint, stating that all the POIs with 5000m, aerial distance should be detected 
     rule.setNumberOfTurns(100); // this has to be increased – otherwise some points will be disconsidered 
     rule.setRouteDistance(10000);//this has to be increased as the real road route will be longer than the aerial distance 
     rule.setMinSpeedIgnoreDistanceAfterTurn(20); //decrease this to evaluate all candidates 
     rule.setMaxDistanceAfterTurn(10000); //increase this to make sure we don't exclude any candidates 
     rule.setEliminateIfUTurn(false); // setting this to true (default) excludes points that require us to make an U-turn to get to them 
     rule.setPlayAudioWarning(false); 
     poiTrackerManager = new SKPOITrackerManager(this); 
     poiTrackerManager.startPOITrackerWithRadius(1500, 0.5); 
     poiTrackerManager.setRuleForPOIType(SKTrackablePOIType.SPEEDCAM, rule); 
    } 
    @Override 
    public void onServerLikeRouteCalculationCompleted(SKRouteJsonAnswer skRouteJsonAnswer) {} 
    @Override 
    public void onOnlineRouteComputationHanging(int i) {} 
    @Override 
    public void onDestinationReached() {} 
    @Override 
    public void onSignalNewAdviceWithInstruction(String s) {} 
    @Override 
    public void onSignalNewAdviceWithAudioFiles(String[] strings, boolean b) {} 
    @Override 
    public void onSpeedExceededWithAudioFiles(String[] strings, boolean b) {} 
    @Override 
    public void onSpeedExceededWithInstruction(String s, boolean b) {} 
    @Override 
    public void onUpdateNavigationState(SKNavigationState skNavigationState) { Log.v(getClass().getName(), "onUpdateNavigationState: " + skNavigationState.toString());} 
    @Override 
    public void onReRoutingStarted() {} 
    @Override 
    public void onFreeDriveUpdated(String s, String s1, SKNavigationState.SKStreetType skStreetType, double v, double v1) {} 
    @Override 
    public void onViaPointReached(int i) {} 
    @Override 
    public void onVisualAdviceChanged(boolean b, boolean b1, SKNavigationState skNavigationState) {} 
    @Override 
    public void onTunnelEvent(boolean b) {} 
    @Override 
    public void onFcdTripStarted(String s) {} 

    @Override 
    public void onUpdatePOIsInRadius(double latitude, double longitude, int radius) { 
     Log.i(getClass().getName(), "onUpdatePOIsInRadius(): "); 
     // set the POIs to be tracked by the POI tracker 
     for (SKTrackablePOI skTrackablePOI : trackablePOIs.values()) { 
      Log.i(getClass().getName(), "onUpdatePOIsInRadius() skTrackablePOI: " + skTrackablePOI); 
     } 
     poiTrackerManager.setTrackedPOIs(SKTrackablePOIType.SPEEDCAM, new ArrayList<SKTrackablePOI>(trackablePOIs.values())); 
    } 

    @Override 
    public void onReceivedPOIs(SKTrackablePOIType type, List<SKDetectedPOI> detectedPois) { 
     Log.i(getClass().getName(), "onReceivedPOIs() detectedPois.size(): " + detectedPois.size()); 
     if (detectedPois.size() == 1 && detectedPois.get(0).getPoiID() == -1) { 
      return; 
     } 
     for (SKDetectedPOI skDetectedPOI : detectedPois) { 
      Log.i(getClass().getName(), "onReceivedPOIs() skDetectedPOI: " + skDetectedPOI); 
      SKAnnotation skAnnotation = new SKAnnotation(skDetectedPOI.getPoiID()); 
      skAnnotation.setAnnotationType(SKAnnotation.SK_ANNOTATION_TYPE_GREEN); 
      skAnnotation.setLocation(trackablePOIs.get(skDetectedPOI.getPoiID()).getCoordinate()); 
      mapView.addAnnotation(skAnnotation, SKAnimationSettings.ANIMATION_PIN_DROP); 
     } 
    } 
} 

我不知道爲什麼跟蹤器不工作。 :(

+0

我們的開發團隊會研究它 – SylviA

回答

0

的規則確定 你需要修改你的邏輯類似於示範項目的東西:

(下面的代碼是在示範項目以復加,MapActivity.java中, onAllRoutesCompleted回調,則currentMapOption == MapOption.POI_TRACKING分支)

  poiTrackingManager.startPOITrackerWithRadius(10000, 0.5); 
      // set warning rules for trackable POIs 
      // SKTrackablePOIType myType =SKTrackablePOIType.forInt(1000); 
      SKTrackablePOIRule rule = new SKTrackablePOIRule(); 
      rule.setAerialDistance(5000); // this would be our main constraint, stating that all the POIs with 5000m, aerial distance should be detected 
      rule.setNumberOfTurns(100); // this has to be increased – otherwise some points will be disconsidered 
      rule.setRouteDistance(10000);//this has to be increased as the real road route will be longer than the aerial distance 
      rule.setMinSpeedIgnoreDistanceAfterTurn(20); //decrease this to evaluate all candidates 
      rule.setMaxDistanceAfterTurn(10000); //increase this to make sure we don't exclude any candidates 
      rule.setEliminateIfUTurn(false); // setting this to true (default) excludes points that require us to make an U-turn to get to them 
      rule.setPlayAudioWarning(false); 
      poiTrackingManager.setRuleForPOIType(SKTrackablePOIType.SPEEDCAM, rule);     
      launchNavigation(); 

在onUpdatePOIsInRadius你必須提供給跟蹤器的「刷新」 POI列表,這個回調會被跟蹤,一旦達到refreshMargin觸發條件。

@Override 
    public void onUpdatePOIsInRadius(double latitude, double longitude, int radius) { 

     // set the POIs to be tracked by the POI tracker 
     // SKTrackablePOIType myType =SKTrackablePOIType.forInt(1000); 
     poiTrackingManager.setTrackedPOIs(SKTrackablePOIType.SPEEDCAM, 
       new ArrayList<SKTrackablePOI>(trackablePOIs.values())); 
    } 

在onReceivedPOIs你會得到關於檢測到的POI的信息:

public void onReceivedPOIs(SKTrackablePOIType type, List<SKDetectedPOI> detectedPois) { 
//add code here to handle the detected POIs 

} 

我已經編輯與上面的代碼香草演示項目(與點的默認定義跟蹤)和我收到很多通知。

根據您跟蹤興趣點的「密度」,您可能希望減少refreshMargin(和觸發POI組更新更頻繁) - 即poiTrackerManager.startPOITrackerWithRadius(5000, 0.1);

另見http://sdkblog.skobbler.com/detecting-tracking-pois-in-your-way/更多分析上市公司POI跟蹤功能

+0

謝謝安藤。您和我的代碼之間的主要區別在於您在初始化POI跟蹤器後啓動導航。我這樣做了,現在在onUpdatePOIsInRadius()中設置了許多跟蹤的POI。但是''onReceivedPOs()''方法仍然不會跟蹤任何內容。如果我在設置POI跟蹤器之前或之後啓動導航,您認爲這很重要嗎? – unlimited101

+0

因此onReceivedPOIs被調用,但detectedPois是空的? – Ando

+0

沒錯。但是detectedPois並不完全是空的。總是有一個檢測到的POI id = -1。在導航模擬模式下,POI檢測可能不起作用? – unlimited101