[英]The location point changes when zooming out
I am developing an windows phone application and have to mark the current location and the destinated location location.But the problem is when the application shows the point normally it shows the correct point but while zooming out , the point's position keeps changing .Below is the code 我正在开发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();
}
}
Below here is the another class regarding coordinates 下面是关于坐标的另一类
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
);
}
}
and hers is the xaml code so that you can see the problem clearly 她是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>
When you zoom out the map size goes smaller on screen and pushpin's (your point position icon/image) size is as it is. 缩小时,地图的大小在屏幕上变小,图钉的(您的点位置图标/图像)大小保持不变。 So visibly you will find that location point is changing its location. 可见,您会发现位置点正在更改其位置。
But again when you zoom in, it will be on the exact place where it should be. 但是再次放大时,它将在应该放置的确切位置。
PS:If location point size also gets decreased while zoom out, at one time user may not see it properly. PS:如果缩小时定位点的大小也变小,则用户可能一次看不到它。
So if you want to set a Pushpin on the map and want it to always shows your current location, you can try this: 因此,如果您想在地图上设置图钉并希望其始终显示您的当前位置,则可以尝试以下操作:
Here the C# code: 这是C#代码:
GeoCoordinate myPosition = null;
UserLocationMarker marker = (UserLocationMarker)this.FindName("UserLocationMarker");
marker.GeoCoordinate = myPosition;
Here the XAML code: 这里是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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.