C# 缩小时,位置点会发生变化

C# 缩小时,位置点会发生变化,c#,xaml,windows-phone-8,location,C#,Xaml,Windows Phone 8,Location,我正在开发一个windows phone应用程序,必须标记当前位置和目标位置。但问题是,当应用程序正常显示点时,它会显示正确的点,但在缩小时,点的位置会不断变化。下面是代码 public partial class Findcar : PhoneApplicationPage { //private static string baseUri = "bingmaps:?"; DbHelper Db_helper = new DbHelper(); int ids = 0;

我正在开发一个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();
    }

    }
她的是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>

我的车的方向

缩小地图时,屏幕上的地图尺寸变小,图钉(您的点位置图标/图像)的尺寸保持不变。所以很明显,你会发现定位点正在改变它的位置

但是,当你再次放大时,它将位于它应该位于的确切位置


注:若在缩小时位置点的大小也减小了,用户可能一次看不清楚

因此,如果您想在地图上设置图钉并希望它始终显示您的当前位置,您可以尝试以下方法:

这里是C代码:

GeoCoordinate myPosition = null;
UserLocationMarker marker = (UserLocationMarker)this.FindName("UserLocationMarker");
marker.GeoCoordinate = myPosition;
<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>
这里是XAML代码:

GeoCoordinate myPosition = null;
UserLocationMarker marker = (UserLocationMarker)this.FindName("UserLocationMarker");
marker.GeoCoordinate = myPosition;
<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>


缩小时,lat long值是否会更改?@dotnet Weblineindia否该值不会更改