2014-03-12 50 views
1

我已將一個GeoCoordinate變量傳遞到了我的地圖類的頁面,但是當我嘗試在地圖上繪製標記時,出現一個錯誤,指出GeoCoordinate is a 'type' but is used as a 'variable'它也給我提供了;PositionOrigin = new Point(0.5, 0.5); 處的語法錯誤, ;如何添加地圖標記到地圖? Windows Phone

我明白,我的語法由於出現此錯誤而必須添加地圖標記不正確。我的問題是我如何糾正這種方法來繪製標記? 我是以正確的方式繪製標記還是存在不同的解決方案?

這是地圖頁面,我通過座標和嘗試添加標記的onNaviagatedTo方法:

protected override void OnNavigatedTo(NavigationEventArgs e) 
     { 
      if (NavigationContext.QueryString.ContainsKey("GeoLat") && NavigationContext.QueryString.ContainsKey("GeoLong")) 
      { 
       var latitude = Convert.ToDouble(NavigationContext.QueryString["GeoLat"]); 
       var longtitude = Convert.ToDouble(NavigationContext.QueryString["GeoLong"]); 
       var MyGeoPosition = new GeoCoordinate(latitude, longtitude); 

       var overlay = new MapOverlay 
       { 
        PositionOrigin = new Point(0.5, 0.5); //syntax error 
        GeoCoordinate = MyGeoPosition; //error thrown here 
        Content = new TextBlock{Text = "My car"}; 

        var ml = new MapLayer { overlay }; 
        MyMap.Layers.Add(ml); 
       }; //syntax error 

      } 
+0

我找到了答案,你對中心佈局問題,但你已被刪除。找到答案? :) –

回答

3

我看來像你錯過了一個等號。

MapOverlay overlay = new MapOverlay() 
{ 
    PositionOrigin = new Point(0.5, 0.5), 
    GeoCoordinate = MyGeoPosition, 
    Content = new TextBlock{Text = "My car"}, 
}; 
MapLayer ml = new MapLayer { overlay }; 
MyMap.Layers.Add(ml); 

或者,你可能只是這樣做有圖釘:

PushPin myPin = new Pushpin(); 
myPin.Location = MyGeoPosition; 
myPin.Content = "My car"; 
MyMap.Children.Add(myPin); 
+0

試過上面的,給我'GeoCoordinate是一個類型,但是像變量一樣使用'也給我語法錯誤在第一行和右括號的分號。任何想法? –

+0

對不起,我只是在複製上面的內容並添加等號 - 修正了語法。 – Deeko

+0

我嘗試了以上,但由於某種原因,當我運行該應用程序,地圖只是顯示未經審查,沒有地圖標記..我錯過了一些東西,它缺少添加標記? –

相關問題