Windows Phone 7 Silverlight控件之--Map的基本控制
这节讲解Map的基本控制,根据经纬度定位,改变地图的焦距。效果图
定位通过经纬度来控制。具体方法是SetView();
它有以下几种类型参数
SetView(LocationRect boundingRectangle);
SetView(GeoCoordinate center, double zoomLevel);
SetView(GeoCoordinate center, double zoomLevel, double heading);
SetView(GeoCoordinate center, double zoomLevel, double heading, double pitch);
ZoomLevel属性用于控制地图的焦距。
在本例中使用的是第一种参数方法。
1.MapBaseControl.xaml
2.MapBaseControl.cs
public partial class MapBaseControl : PhoneApplicationPage
{
public MapBaseControl()
{
InitializeComponent();
}
private void ApplicationBarIconButton_Click(object sender, EventArgs e)
{
this.locate.Visibility = Visibility.Visible;
}
private void btnLocate_Click(object sender, RoutedEventArgs e)
{
//纬度
double latitude = 0;
//经度
double longitude = 0;
//焦距
double zoomLevel = 1d;
double.TryParse(txtLatitude.Text, out latitude);
double.TryParse(txtLongitude.Text, out longitude);
double.TryParse(txtZoomlevel.Text, out zoomLevel);
this.myMap.SetView(new LocationRect(new GeoCoordinate(latitude, longitude), 80, 80));
this.myMap.ZoomLevel = zoomLevel;
this.locate.Visibility = Visibility.Collapsed;
}
}
页:
[1]