1.อยากได้ข้อแนะนำการสร้างแผนที่ wp8
ถ้าต้องการใช้ map ของ google โดยใช้ภาษาC# กับ xaml
2. ลองสร้างmap ที่จะค้นหาตำแหน่งของตนเอง และจะแสดงตำแหน่ง(กำหนดพิกัดเอง)
และต้องการสร้างปุ่ม route เพื่อให้แสดงเส้นทางจาก my location ไปยังสถานีนั้นๆ
Code
public partial class NearMapPage : PhoneApplicationPage
{
public NearMapPage()
{
InitializeComponent();
ShowMyLocationOnTheMap();
Map MyMap = new Map();
MyMap.Center = new GeoCoordinate(47.6097, -122.3331);
MyMap.ZoomLevel = 12;
MyMap.LandmarksEnabled = true;
MyMap.PedestrianFeaturesEnabled = true;
ContentPanel.Children.Add(MyMap);
}
//ApplicationId and AuthenticationToken properties after the first Map control has been loaded
private void myMapControl_Loaded(object sender, RoutedEventArgs e)
{
Microsoft.Phone.Maps.MapsSettings.ApplicationContext.ApplicationId = "ApplicationId";
Microsoft.Phone.Maps.MapsSettings.ApplicationContext.AuthenticationToken = "AuthenticationToken";
}
private void ApplicationBarSearchButton_click(object sender, EventArgs e)
{ }
//near1
private async void ShowMyLocationOnTheMap()
{
// Get my current location.
Geolocator myGeolocator = new Geolocator();
Geoposition myGeoposition = await myGeolocator.GetGeopositionAsync();
Geocoordinate myGeocoordinate = myGeoposition.Coordinate;
GeoCoordinate myGeoCoordinate = CoordinateConverter.ConvertGeocoordinate(myGeocoordinate);
// Make my current location the center of the Map.
this.mapWithMyLocation.Center = myGeoCoordinate;
this.mapWithMyLocation.ZoomLevel = 16;
// Create a small circle to mark the current location.
Ellipse myCircle1 = new Ellipse();
myCircle1.Fill = new SolidColorBrush(Colors.Blue);
myCircle1.Height = 20;
myCircle1.Width = 20;
myCircle1.Opacity = 50;
// Create a MapOverlay to contain the circle.
MapOverlay myLocationOverlay = new MapOverlay();
myLocationOverlay.Content = myCircle1;
myLocationOverlay.PositionOrigin = new Point(0.5, 0.5);
myLocationOverlay.GeoCoordinate = myGeoCoordinate;
// Create a MapLayer to contain the MapOverlay.
MapLayer myLocationLayer = new MapLayer();
myLocationLayer.Add(myLocationOverlay);
// Add the MapLayer to the Map.
mapWithMyLocation.Layers.Add(myLocationLayer);
}
private async void ApplicationBarRouteButton_click(object sender, EventArgs e)
{
// Create a small circle to mark the current location.
Ellipse myCircle2 = new Ellipse();
myCircle2.Fill = new SolidColorBrush(Colors.Red);
myCircle2.Height = 20;
myCircle2.Width = 20;
myCircle2.Opacity = 50;
// Create a MapOverlay to contain the circle.
MapOverlay myLocationOverlay1 = new MapOverlay();
myLocationOverlay1.Content = myCircle2;
myLocationOverlay1.PositionOrigin = new Point(0.5, 0.5);
myLocationOverlay1.GeoCoordinate = new GeoCoordinate(13.728061, 100.777149);
//RouteQuery
// Create a MapLayer to contain the MapOverlay
MapLayer myLocationLayer = new MapLayer();
myLocationLayer.Add(myLocationOverlay1);
// Add the MapLayer to the Map.
mapWithMyLocation.Layers.Add(myLocationLayer);
}
}