2014-01-15 74 views
0

我正在尋找WP7.1和WP8的解決方案。我正在搜索,我想我不能使用Driving directions for WP7,對不對?我試圖使用MapsDirectionsTask,但即使如果我添加引用所需的東西仍然無法解析符號。所以我猜WP7是BingMapsDirectionsTask。我得到我的應用程序運行,但當我試圖從我的位置找到方向解決我得到錯誤,找不到方向。那麼有什麼可能是錯的?我嘗試了多個地址,有或沒有地理座標等。我是否需要首先下載我的手機?使用Bing地圖方向是否有任何限制?有沒有更好的方法可以在WP7中工作?Windows Phone 7 - 放置的方向

編輯: 我嘗試了來自MSDN示例代碼MapsDirectionsTask和BingMapsDirectionsTask。正如我寫的,我無法獲得MapsDirectionsTask的工作,因爲VS無法找到該參考(但我添加了文章中的內容庫)。

BingMapsDirectionsTask bingMapsDirectionsTask = new BingMapsDirectionsTask(); 
// here I tried different addresses and I tried to add geocoordinates to these addresses    
LabeledMapLocation spaceNeedleLML = new LabeledMapLocation("Space Needle", null); 
bingMapsDirectionsTask.End = spaceNeedleLML; 
bingMapsDirectionsTask.Show(); 

Bing地圖只是說當加載地圖上的任意位置點擊它給你方向,從您目前的位置抽頭位置是找不到方向

+0

請分享(代碼)你已經嘗試過 –

回答

0

試試這個,這需要從一個地方作爲你的當前位置和位置是您點的地圖上,通過這個代碼替換裏面的命名空間UR內容,這工作正常

 public partial class MainPage : PhoneApplicationPage 
{ 
    GeoCoordinateWatcher watcher; 

    // Constructor 
    public MainPage() 
    { 
     InitializeComponent(); 

     LoadWatcher(); 
    } 

    private void LoadWatcher() 
    { 
     if (watcher == null) 
     { 
      watcher = new GeoCoordinateWatcher(GeoPositionAccuracy.High); 
      watcher.MovementThreshold = 20; 

      watcher.StatusChanged += new EventHandler<GeoPositionStatusChangedEventArgs>(watcher_StatusChanged); 
      watcher.PositionChanged += new EventHandler<GeoPositionChangedEventArgs<GeoCoordinate>>(watcher_PositionChanged); 
     } 

     watcher.Start(); 
    } 

    void watcher_PositionChanged(object sender, GeoPositionChangedEventArgs<GeoCoordinate> e) 
    { 
     myMap.SetView(e.Position.Location, 10); 
    } 

    void watcher_StatusChanged(object sender, GeoPositionStatusChangedEventArgs e) 
    { 
     switch (e.Status) 
     { 
      case GeoPositionStatus.Disabled: 
       statusTextBlock.Text = "location is not functioning on this device"; 
       break; 

      case GeoPositionStatus.Initializing: 
       statusTextBlock.Text = "Initializing"; 
       break; 

      case GeoPositionStatus.NoData: 
       statusTextBlock.Text = "location data is not available."; 
       break; 

      case GeoPositionStatus.Ready: 
       statusTextBlock.Text = "location data is available."; 
       break; 
     } 
    } 

    private void map1_Tap(object sender, GestureEventArgs e) 
    { 
     var position = e.GetPosition(myMap); 
     var geoCoordinate = new GeoCoordinate(); 
     geoCoordinate = myMap.ViewportPointToLocation(position); 

     OpenDirectionTo(geoCoordinate); 
    } 

    private void OpenDirectionTo(GeoCoordinate locationY) 
    { 
     BingMapsDirectionsTask directionTask = new BingMapsDirectionsTask(); 
     directionTask.End = new LabeledMapLocation("Your tapped location", locationY); 
     directionTask.Show(); 
    } 
} 

轉寄此文章 Directions