我正在开发一个Windows手机应用程序,并且必须标记当前位置和目标位置位置。但问题是当应用程序通常显示正确点时,但在缩小时,点的位置不断变化。以下是代码
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>
答案 0 :(得分:0)
当您缩小时,地图尺寸在屏幕上变小,而图钉(您的点位置图标/图像)尺寸就是原样。因此,您会发现位置点正在改变其位置。
但是当你放大时,它会在确切的位置。
P.S:如果缩小时位置点大小也减小,用户可能无法正常看到它。
答案 1 :(得分:0)
因此,如果您想在地图上设置图钉并希望它始终显示您当前的位置,您可以试试这个:
这里是C#代码:
GeoCoordinate myPosition = null;
UserLocationMarker marker = (UserLocationMarker)this.FindName("UserLocationMarker");
marker.GeoCoordinate = myPosition;
这里是XAML代码:
<toolkit:UserLocationMarker x:Name="UserLocationMarker" Visibility="Collapsed">
<toolkit:UserLocationMarker.Template>
<ControlTemplate TargetType="toolkit:UserLocationMarker">
<StackPanel>
<Border x:Name="pinBorder" Background="Black" Width="30" Height="30" CornerRadius="30" HorizontalAlignment="Center" VerticalAlignment="Center">
<Ellipse x:Name="pinEllipse" Fill="#FF00A300" Stroke="White" StrokeThickness="2" Width="24" Height="24" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
</StackPanel>
</ControlTemplate>
</toolkit:UserLocationMarker.Template>