【发布时间】:2014-11-13 13:11:26
【问题描述】:
我正在开发一个 windows phone 应用程序,必须标记当前位置和目标位置位置。但问题是当应用程序正常显示点时,它显示正确的点,但在缩小时,点的位置不断变化。下面是代码
public partial class Findcar : PhoneApplicationPage
{
//private static string baseUri = "bingmaps:?";
DbHelper Db_helper = new DbHelper();
int ids = 0;
historyTableSQlite lists = new historyTableSQlite();
//historyTableSQlite list2 = new historyTableSQlite();
public static double lt {get; set;}
public static double lg { get; set; }
public static double lt2 { get; set; }
public static double lg2 { get; set; }
//String fl = Checkin.Floor_st;
//String zo = Checkin.Zone_st;
GeoCoordinate currentLocation = null;
UCCustomToolTip _tooltip = new UCCustomToolTip();
Geolocator myGeolocator = new Geolocator();
public Findcar()
{
InitializeComponent();
GetLocation();
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
lists = Db_helper.Readlats(lists.Id);
//list2 = Db_helper.ReadContact(History.Selected_HistoryId);
lt = lists.latitude;
lg = lists.longtitude;
if (lt2 != 0.0D && lg2 != 0.0D)
{
lt = lt2;
lg = lg2;
}
// Selected_HistoryId = int.Parse(NavigationContext.QueryString["SelectedHistoryID"]);
}
private async void GetLocation()
{
// Get current location.
Geoposition myGeoposition = await myGeolocator.GetGeopositionAsync(maximumAge: TimeSpan.FromMinutes(5), timeout: TimeSpan.FromSeconds(10));
Geocoordinate myGeocoordinate = myGeoposition.Coordinate;
currentLocation = CoordinateConverter.ConvertGeocoordinate(myGeocoordinate);
MapDisplay(currentLocation);
}
private void MapDisplay(GeoCoordinate LocationsData)
{
ReverseGeocodeQuery Query = new ReverseGeocodeQuery()
{
GeoCoordinate = new GeoCoordinate(LocationsData.Latitude, LocationsData.Longitude)
};
Query.QueryCompleted += Query_QueryCompleted;
Query.QueryAsync();
MapOverlay mylocationOverlay = new MapOverlay();
mylocationOverlay.Content = _tooltip;
mylocationOverlay.GeoCoordinate = LocationsData;
MapLayer myLocationLayer = new MapLayer();
myLocationLayer.Add(mylocationOverlay);
mymap.Layers.Add(myLocationLayer);
mymap.Center = LocationsData;
}
void Query_QueryCompleted(object sender, QueryCompletedEventArgs<IList<MapLocation>> e)
{
_tooltip.Description = "";
StringBuilder _description = new StringBuilder();
foreach (var item in e.Result)
{
if (!(item.Information.Address.BuildingName == ""))
{
_description.Append(item.Information.Address.BuildingName + ", ");
}
if (!(item.Information.Address.BuildingFloor == ""))
{
_description.Append(item.Information.Address.BuildingFloor + ", ");
}
if (!(item.Information.Address.Street == ""))
{
_description.Append(item.Information.Address.Street + ", ");
}
if (!(item.Information.Address.District == ""))
{
_description.Append(item.Information.Address.District + ",");
}
if (!(item.Information.Address.City == ""))
{
_description.Append(item.Information.Address.City + ", ");
}
if (!(item.Information.Address.State == ""))
{
_description.Append(item.Information.Address.State + ", ");
}
if (!(item.Information.Address.Street == ""))
{
_description.Append(item.Information.Address.Street + ", ");
}
if (!(item.Information.Address.Country == ""))
{
_description.Append(item.Information.Address.Country + ", ");
}
if (!(item.Information.Address.Province == ""))
{
_description.Append(item.Information.Address.Province + ", ");
}
if (!(item.Information.Address.PostalCode == ""))
{
_description.Append(item.Information.Address.PostalCode);
}
_tooltip.Description = "Your car :"+_description.ToString();
_tooltip.FillDescription();
break;
}
}
private async void TextBlock_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
Geoposition myGeoposition = await myGeolocator.GetGeopositionAsync(maximumAge: TimeSpan.FromMinutes(5), timeout: TimeSpan.FromSeconds(10));
BingMapsDirectionsTask bing = new BingMapsDirectionsTask()
{
//Giving label and coordinates to starting and ending points.
Start = new LabeledMapLocation("You are here", new GeoCoordinate(myGeoposition.Coordinate.Latitude, myGeoposition.Coordinate.Longitude)),
//This is the place where I want to get the latitude and longtitude from the database
End = new LabeledMapLocation("Your car", new GeoCoordinate(Findcar.lt, Findcar.lg))
};
// Launching Bing Maps Direction Tasks
bing.Show();
}
}
下面是关于坐标的另一个类
public static GeoCoordinate ConvertGeocoordinate(Geocoordinate geocoordinate)
{
//historyTableSQlite lists = new historyTableSQlite();
//DbHelper Db_helper = new DbHelper();
// double lt;
// double lg;
//lists = Db_helper.Readlats(lists.Id);
//lt = lists.latitude;
//lg = lists.longtitude;
return new GeoCoordinate
(
Findcar.lt,
Findcar.lg,
geocoordinate.Altitude ?? Double.NaN,
geocoordinate.Accuracy,
geocoordinate.AltitudeAccuracy ?? Double.NaN,
geocoordinate.Speed ?? Double.NaN,
geocoordinate.Heading ?? Double.NaN
);
}
}
她的就是xaml代码,让你看清楚问题
<phone:PhoneApplicationPage
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:maps="clr-namespace:Microsoft.Phone.Maps.Controls;assembly=Microsoft.Phone.Maps" xmlns:Toolkit="clr-namespace:Microsoft.Phone.Maps.Toolkit;assembly=Microsoft.Phone.Controls.Toolkit"
xmlns:Location="clr-namespace:System.Device.Location;assembly=System.Device"
xmlns:maptk="clr-namespace:Microsoft.Phone.Maps.Toolkit;assembly=Microsoft.Phone.Controls.Toolkit"
x:Class="SmartParking.Findcar"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
mc:Ignorable="d"
shell:SystemTray.IsVisible="True">
<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!--TitlePanel contains the name of the application and page title-->
<StackPanel Grid.Row="0" Margin="12,17,0,28">
<TextBlock Text="Smart Parking" Style="{StaticResource PhoneTextNormalStyle}"/>
<TextBlock Text="Find my car" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
</StackPanel>
<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<StackPanel>
<!--<TextBlock TextWrapping="Wrap" FontSize="40" Text="Wher is my car" FontWeight="Bold" Foreground="Red"/>
--><!--<TextBlock x:Name="Floor_fc" TextWrapping="Wrap" Text="Floor : " FontSize="29.333"/>
<TextBlock x:Name="Zone_fc" TextWrapping="Wrap" Text="Zone :" FontSize="29.333"/>--><!--
<TextBlock TextWrapping="Wrap" Text="Check on the maps" FontSize="29.333"/>-->
<!--<maps:Map Height="232" Tap="Map_Tap" PedestrianFeaturesEnabled="True" LandmarksEnabled="True" ColorMode="Dark"/>-->
<maps:Map Height="519" Grid.Row="1" x:Name="mymap" Margin="0" ZoomLevel="16">
<maptk:MapExtensions.Children>
</maptk:MapExtensions.Children>
</maps:Map>
<Button Tap="TextBlock_Tap">Direction to my car</Button>
</StackPanel>
</Grid>
</Grid>
【问题讨论】:
-
缩小时,lat long 值会改变吗?
-
@dotnet Weblineindia 否,值不变
标签: c# xaml windows-phone-8 location