forked from phonegap/phonegap-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPGMapLauncher.cs
124 lines (104 loc) · 4.19 KB
/
PGMapLauncher.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Tasks;
using Microsoft.Phone.Controls;
using System.Device.Location;
using System.Runtime.Serialization;
using System.Diagnostics;
namespace WP7CordovaClassLib.Cordova.Commands
{
public class PGMapLauncher : Cordova.Commands.BaseCommand
{
[DataContract]
public class SearchOptions
{
[DataMember(IsRequired = false, Name = "searchTerm")]
public string SearchTerm { get; set; }
[DataMember(IsRequired = false, Name = "center")]
public Coordinates Center;
}
[DataContract]
public class Coordinates
{
[DataMember(IsRequired = false, Name = "latitude")]
public double Latitude;
[DataMember(IsRequired = false, Name = "longitude")]
public double Longitude;
}
[DataContract]
public class LabeledCoordinates
{
[DataMember(IsRequired = false, Name = "coordinates")]
public Coordinates Coordinates;
[DataMember(IsRequired = false, Name = "label")]
public string Label;
}
[DataContract]
public class GetDirectionsOptions
{
[DataMember(IsRequired = false, Name = "startPosition")]
public LabeledCoordinates Start;
[DataMember(IsRequired = true, Name = "endPosition")]
public LabeledCoordinates End;
}
public void searchNear(string options)
{
SearchOptions searchOptions = JSON.JsonHelper.Deserialize<SearchOptions>(options);
BingMapsTask bingMapsTask = new BingMapsTask();
//Omit the Center property to use the user's current location.
if (searchOptions.Center != null)
{
bingMapsTask.Center = new GeoCoordinate(searchOptions.Center.Latitude, searchOptions.Center.Longitude);
}
if (searchOptions.SearchTerm != null)
{
bingMapsTask.SearchTerm = searchOptions.SearchTerm;
bingMapsTask.Show();
}
else
{
Debug.WriteLine("Error::searchTerm must be specified for map searching");
}
}
public void getDirections(string options)
{
GetDirectionsOptions directionOptions = JSON.JsonHelper.Deserialize<GetDirectionsOptions>(options);
BingMapsDirectionsTask bingMapsDirectionsTask = new BingMapsDirectionsTask();
// You can specify a label and a geocoordinate for the end point.
if (directionOptions.Start != null)
{
LabeledMapLocation startLML = new LabeledMapLocation();
startLML.Location = new GeoCoordinate(directionOptions.Start.Coordinates.Latitude, directionOptions.Start.Coordinates.Longitude);
if (directionOptions.Start.Label != null)
{
startLML.Label = directionOptions.Start.Label;
}
bingMapsDirectionsTask.Start = startLML;
}
// If you set the geocoordinate parameter to null, the label parameter is used as a search term.
if (directionOptions.End != null)
{
LabeledMapLocation endLML = new LabeledMapLocation();
if (directionOptions.End.Coordinates != null)
{
endLML.Location = new GeoCoordinate(directionOptions.End.Coordinates.Latitude, directionOptions.End.Coordinates.Longitude);
}
if (directionOptions.End.Label != null)
{
endLML.Label = directionOptions.End.Label;
}
bingMapsDirectionsTask.End = endLML;
}
// If bingMapsDirectionsTask.Start is not set, the user's current location is used as the start point.
bingMapsDirectionsTask.Show();
}
}
}