├── GDirectionsApiUtils
├── .classpath
├── .gitignore
├── .project
├── AndroidManifest.xml
├── delivery
│ └── gdirectionsapiutils_gps4030500.jar
├── gen
│ └── com
│ │ └── android2ee
│ │ └── formations
│ │ └── librairies
│ │ └── google
│ │ └── map
│ │ └── utils
│ │ └── BuildConfig.java
├── libs
│ └── google-play-services.jar
├── neededLibs.txt
├── proguard-project.txt
├── project.properties
├── res
│ ├── drawable-hdpi
│ │ └── ic_launcher.png
│ ├── drawable-mdpi
│ │ └── ic_launcher.png
│ ├── drawable-xhdpi
│ │ └── ic_launcher.png
│ ├── values-v11
│ │ └── styles.xml
│ ├── values-v14
│ │ └── styles.xml
│ └── values
│ │ ├── strings.xml
│ │ └── styles.xml
└── src
│ └── com
│ └── android2ee
│ └── formation
│ └── librairies
│ └── google
│ └── map
│ └── utils
│ └── direction
│ ├── DCACallBack.java
│ ├── GDirectionsApiUtils.java
│ ├── IGDFormatter.java
│ ├── model
│ ├── GDColor.java
│ ├── GDLegs.java
│ ├── GDPath.java
│ ├── GDPoint.java
│ └── GDirection.java
│ ├── parser
│ └── DirectionsJSONParser.java
│ └── util
│ ├── Avoid.java
│ ├── GDirectionData.java
│ ├── GDirectionMapsOptions.java
│ ├── Mode.java
│ ├── UnitSystem.java
│ └── Util.java
└── README.md
/GDirectionsApiUtils/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/GDirectionsApiUtils/.gitignore:
--------------------------------------------------------------------------------
1 | /bin
2 |
--------------------------------------------------------------------------------
/GDirectionsApiUtils/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | GDirectionsApiUtils
4 |
5 |
6 |
7 |
8 |
9 | com.android.ide.eclipse.adt.ResourceManagerBuilder
10 |
11 |
12 |
13 |
14 | com.android.ide.eclipse.adt.PreCompilerBuilder
15 |
16 |
17 |
18 |
19 | org.eclipse.jdt.core.javabuilder
20 |
21 |
22 |
23 |
24 | com.android.ide.eclipse.adt.ApkBuilder
25 |
26 |
27 |
28 |
29 |
30 | com.android.ide.eclipse.adt.AndroidNature
31 | org.eclipse.jdt.core.javanature
32 |
33 |
34 |
--------------------------------------------------------------------------------
/GDirectionsApiUtils/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
9 |
10 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/GDirectionsApiUtils/delivery/gdirectionsapiutils_gps4030500.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MathiasSeguy-Android2EE/GDirectionsApiUtils/5d396e486e3fec2da8402afb36076212ab815a41/GDirectionsApiUtils/delivery/gdirectionsapiutils_gps4030500.jar
--------------------------------------------------------------------------------
/GDirectionsApiUtils/gen/com/android2ee/formations/librairies/google/map/utils/BuildConfig.java:
--------------------------------------------------------------------------------
1 | /** Automatically generated file. DO NOT MODIFY */
2 | package com.android2ee.formations.librairies.google.map.utils;
3 |
4 | public final class BuildConfig {
5 | public final static boolean DEBUG = true;
6 | }
--------------------------------------------------------------------------------
/GDirectionsApiUtils/libs/google-play-services.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MathiasSeguy-Android2EE/GDirectionsApiUtils/5d396e486e3fec2da8402afb36076212ab815a41/GDirectionsApiUtils/libs/google-play-services.jar
--------------------------------------------------------------------------------
/GDirectionsApiUtils/neededLibs.txt:
--------------------------------------------------------------------------------
1 | The only needed library for this project is google-play-services
2 | because of the imports:
3 | import com.google.android.gms.maps.GoogleMap;
4 | import com.google.android.gms.maps.model.BitmapDescriptorFactory;
5 | import com.google.android.gms.maps.model.LatLng;
6 | import com.google.android.gms.maps.model.MarkerOptions;
7 | import com.google.android.gms.maps.model.PolylineOptions;
8 | in GDirectionsApiUtils
9 | And
10 | import com.google.android.gms.maps.model.LatLng;
11 | in GDirection and GDPoint
--------------------------------------------------------------------------------
/GDirectionsApiUtils/proguard-project.txt:
--------------------------------------------------------------------------------
1 | # To enable ProGuard in your project, edit project.properties
2 | # to define the proguard.config property as described in that file.
3 | #
4 | # Add project specific ProGuard rules here.
5 | # By default, the flags in this file are appended to flags specified
6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt
7 | # You can edit the include path and order by changing the ProGuard
8 | # include property in project.properties.
9 | #
10 | # For more details, see
11 | # http://developer.android.com/guide/developing/tools/proguard.html
12 |
13 | # Add any project specific keep options here:
14 |
15 | # If your project uses WebView with JS, uncomment the following
16 | # and specify the fully qualified class name to the JavaScript interface
17 | # class:
18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
19 | # public *;
20 | #}
21 |
--------------------------------------------------------------------------------
/GDirectionsApiUtils/project.properties:
--------------------------------------------------------------------------------
1 | # This file is automatically generated by Android Tools.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must be checked in Version Control Systems.
5 | #
6 | # To customize properties used by the Ant build system edit
7 | # "ant.properties", and override values to adapt the script to your
8 | # project structure.
9 | #
10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
12 |
13 | # Project target.
14 | target=android-21
15 | android.library=true
16 | android.library.reference.1=../../../adt-bundle-linux-x86_64/sdk/extras/google/google_play_services/libproject/google-play-services_lib
17 |
--------------------------------------------------------------------------------
/GDirectionsApiUtils/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MathiasSeguy-Android2EE/GDirectionsApiUtils/5d396e486e3fec2da8402afb36076212ab815a41/GDirectionsApiUtils/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/GDirectionsApiUtils/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MathiasSeguy-Android2EE/GDirectionsApiUtils/5d396e486e3fec2da8402afb36076212ab815a41/GDirectionsApiUtils/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/GDirectionsApiUtils/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MathiasSeguy-Android2EE/GDirectionsApiUtils/5d396e486e3fec2da8402afb36076212ab815a41/GDirectionsApiUtils/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/GDirectionsApiUtils/res/values-v11/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/GDirectionsApiUtils/res/values-v14/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/GDirectionsApiUtils/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | GDirectionsApiUtils
4 |
5 |
6 |
--------------------------------------------------------------------------------
/GDirectionsApiUtils/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
14 |
15 |
16 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/GDirectionsApiUtils/src/com/android2ee/formation/librairies/google/map/utils/direction/DCACallBack.java:
--------------------------------------------------------------------------------
1 | /**
2 | * - GoogleMapSample
3 | * - com.android2ee.formation.librairies.google.map.utils.direction
4 | * - 12 sept. 2013
5 | *
6 | * - ======================================================
7 | *
8 | * - Projet : Mathias Seguy Project
9 | * - Produit par MSE.
10 | *
11 | /**
12 | *
13 | * Android Tutorial, An Android2EE's project.
14 | * Produced by Dr. Mathias SEGUY.
15 | * Delivered by http://android2ee.com/
16 | * Belongs to Mathias Seguy
17 | ****************************************************************************************************************
18 | * This code is free for any usage except training and can't be distribute.
19 | * The distribution is reserved to the site http://android2ee.com.
20 | * The intelectual property belongs to Mathias Seguy.
21 | * http://mathias-seguy.developpez.com/
22 | *
23 | * *****************************************************************************************************************
24 | * Ce code est libre de toute utilisation mais n'est pas distribuable.
25 | * Sa distribution est reservée au site http://android2ee.com.
26 | * Sa propriété intellectuelle appartient à Mathias Seguy.
27 | * http://mathias-seguy.developpez.com/
28 | * *****************************************************************************************************************
29 | */
30 | package com.android2ee.formation.librairies.google.map.utils.direction;
31 |
32 | import java.util.List;
33 |
34 | import com.android2ee.formation.librairies.google.map.utils.direction.model.GDirection;
35 |
36 |
37 |
38 | /**
39 | * @author Mathias Seguy (Android2EE)
40 | * @goals
41 | * This class aims to:
42 | *
43 | */
44 | public interface DCACallBack {
45 |
46 | public void onDirectionLoaded(List directions);
47 | }
48 |
--------------------------------------------------------------------------------
/GDirectionsApiUtils/src/com/android2ee/formation/librairies/google/map/utils/direction/GDirectionsApiUtils.java:
--------------------------------------------------------------------------------
1 | /**
2 | * - GoogleMapSample
3 | * - com.android2ee.formation.librairies.google.map.utils.direction
4 | * - 12 sept. 2013
5 | *
6 | * - ======================================================
7 | *
8 | * - Projet : Mathias Seguy Project
9 | * - Produit par MSE.
10 | *
11 | /**
12 | *
13 | * Android Tutorial, An Android2EE's project.
14 | * Produced by Dr. Mathias SEGUY.
15 | * Delivered by http://android2ee.com/
16 | * Belongs to Mathias Seguy
17 | ****************************************************************************************************************
18 | * This code is free for any usage except training and can't be distribute.
19 | * The distribution is reserved to the site http://android2ee.com.
20 | * The intelectual property belongs to Mathias Seguy.
21 | * http://mathias-seguy.developpez.com/
22 | *
23 | * *****************************************************************************************************************
24 | * Ce code est libre de toute utilisation mais n'est pas distribuable.
25 | * Sa distribution est reservée au site http://android2ee.com.
26 | * Sa propriété intellectuelle appartient à Mathias Seguy.
27 | * http://mathias-seguy.developpez.com/
28 | * *****************************************************************************************************************
29 | */
30 | package com.android2ee.formation.librairies.google.map.utils.direction;
31 |
32 | import java.util.ArrayList;
33 | import java.util.List;
34 |
35 | import android.graphics.Color;
36 | import android.os.AsyncTask;
37 |
38 | import com.android2ee.formation.librairies.google.map.utils.direction.model.GDColor;
39 | import com.android2ee.formation.librairies.google.map.utils.direction.model.GDLegs;
40 | import com.android2ee.formation.librairies.google.map.utils.direction.model.GDPath;
41 | import com.android2ee.formation.librairies.google.map.utils.direction.model.GDPoint;
42 | import com.android2ee.formation.librairies.google.map.utils.direction.model.GDirection;
43 | import com.android2ee.formation.librairies.google.map.utils.direction.util.GDirectionData;
44 | import com.android2ee.formation.librairies.google.map.utils.direction.util.GDirectionMapsOptions;
45 | import com.android2ee.formation.librairies.google.map.utils.direction.util.Util;
46 | import com.google.android.gms.maps.GoogleMap;
47 | import com.google.android.gms.maps.model.BitmapDescriptorFactory;
48 | import com.google.android.gms.maps.model.Marker;
49 | import com.google.android.gms.maps.model.MarkerOptions;
50 | import com.google.android.gms.maps.model.PolylineOptions;
51 |
52 | /**
53 | * @author Mathias Seguy (Android2EE)
54 | * @goals
55 | * This class aims to make a layer over the Direction Api.
56 | * To have a Google Direction and Draw it You just have to:
57 | *
58 | * - Implements the DCACallBack and its method public void onDirectionLoaded(GDirection
59 | * direction)
60 | * - Then you call GDirectionApiUtils.getDirection(DCACallBack, start point, end point,
61 | * GDirectionsApiUtils.MODE_***); When the GDirection is build, the DCACallBack is called
62 | * giving you the GDirection you are waiting for.
63 | * - Then you can handle yourself the GDirection or you can call drawGDirection(GDirection
64 | * direction, GoogleMap map)
65 | *
66 | * d
67 | * public class MainActivity extends ActionBarActivity implements DCACallBack {
68 | * private void getDirections(LatLng point) {
69 | * GDirectionsApiUtils.getDirection(this, mDeviceLatlong, point,
70 | * GDirectionsApiUtils.MODE_WALKING);
71 | * }
72 | * public void onDirectionLoaded(GDirection direction) {
73 | * Log.e("MainActivity", "onDirectionLoaded : Draw GDirections Called with path " +
74 | * direction);
75 | * // Display the direction or use the DirectionsApiUtils
76 | * GDirectionsApiUtils.drawGDirection(direction, mMap);
77 | * }
78 | */
79 | public class GDirectionsApiUtils {
80 |
81 | /******************************************************************************************/
82 | /** Public Method **************************************************************************/
83 | /******************************************************************************************/
84 |
85 | /**
86 | * Draw on the given map the given GDirection object
87 | *
88 | * @param direction
89 | * The google direction to draw
90 | * @param map
91 | * The map to draw on
92 | */
93 | public static void drawGDirection(GDirection direction, GoogleMap map){
94 | drawGDirection(direction, map, null);
95 | }
96 |
97 |
98 | /**
99 | * Draw on the given map the given GDirection object
100 | *
101 | * @param direction
102 | * The google direction to draw
103 | * @param map
104 | * The map to draw on
105 | * @param mapsOptions
106 | * mapsOptions to draw on google maps
107 | */
108 | public static void drawGDirection(GDirection direction, GoogleMap map, GDirectionMapsOptions mapsOptions) {
109 | // The polylines option to create polyline
110 | PolylineOptions lineOptions = null;
111 | // index of GDPoint within the current GDPath
112 | int i = 0;
113 | // index of the current GDPath
114 | int pathIndex = 0;
115 | // index of the current GDLegs
116 | int legsIndex = 0;
117 | ArrayList colors = null;
118 | if (mapsOptions != null) {
119 | colors = mapsOptions.getColors();
120 | }
121 |
122 | IGDFormatter formatter = null;
123 | if (mapsOptions != null) {
124 | formatter = mapsOptions.getFormatter();
125 | }
126 |
127 | // Browse the directions' legs and then the leg's paths
128 | for (GDLegs legs : direction.getLegsList()) {
129 | for (GDPath path : legs.getPathsList()) {
130 | // Create the polyline
131 | if (mapsOptions != null) {
132 | lineOptions = mapsOptions.getPolylineOptions();
133 | } else {
134 | lineOptions = new PolylineOptions();
135 | // A 5 width Polyline please
136 | lineOptions.width(5);
137 | // color options (alternating green/blue path)
138 | if (legsIndex % 2 == 0) {
139 | lineOptions.color(Color.GREEN);
140 | } else {
141 | lineOptions.color(Color.BLUE);
142 | }
143 | }
144 | // manage indexes
145 | i = 0;
146 | pathIndex++;
147 | // browse the GDPoint that define the path
148 | for (GDPoint point : path.getPath()) {
149 | i++;
150 | // Add the point to the polyline
151 | lineOptions.add(point.getLatLng());
152 | // Mark the last GDPoint of the path with a HUE_AZURE marker
153 | if (i == path.getPath().size() - 1) {
154 | // create marker
155 | Marker marker = map.addMarker(new MarkerOptions().position(point.getLatLng())
156 | .title(formatter != null ? formatter.getTitle(path) : "Step " + i)
157 | .snippet(formatter != null ? formatter.getSnippet(path) : "Step " + i)
158 | .icon( ((colors != null && colors.size() > 0) ?
159 | BitmapDescriptorFactory.defaultMarker(colors.get(legsIndex % colors.size()).colorPin) :
160 | BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE))));
161 | // if we have a custom snippet call contents
162 | if (formatter != null && formatter.isInfoWindows()) {
163 | formatter.setContents(marker, direction, legs, path);
164 | marker.showInfoWindow();
165 | }
166 | }
167 | }
168 |
169 | // Override polyline color
170 | if (colors != null && colors.size() > 0) {
171 | lineOptions.color(colors.get(legsIndex % colors.size()).colorLine);
172 | }
173 | // Drawing polyline in the Google Map for the route
174 | map.addPolyline(lineOptions);
175 |
176 | }
177 | legsIndex++;
178 | }
179 | }
180 |
181 | /**
182 | * Find the direction between two points on the maps (direction is the path to follow to go from
183 | * start to end points)
184 | *
185 | * @param callback
186 | * The DCACallBack to prevent when data have been retrieve and built. It will receive
187 | * a GDirection
188 | * @param builder
189 | * builder GDirection
190 | */
191 | public static void getDirection(DCACallBack callback, GDirectionData data) {
192 | GoogleDirectionAsyncRestCall async = new GoogleDirectionAsyncRestCall(callback);
193 | async.execute(data);
194 | }
195 |
196 | /******************************************************************************************/
197 | /** Private Method : The big dark gas factory **************************************************************************/
198 | /******************************************************************************************/
199 |
200 | /**
201 | * @author Mathias Seguy (Android2EE)
202 | * mode (defaults to driving) — Specifies the mode of transport to use when calculating directions. Valid values are specified in Travel Modes. If you set the mode to "transit" you must also specify either a departure_time or an arrival_time.
203 | * waypoints — Specifies an array of waypoints. Waypoints alter a route by routing it through the specified location(s). A waypoint is specified as either a latitude/longitude coordinate or as an address which will be geocoded. Waypoints are only supported for driving, walking and bicycling directions. (For more information on waypoints, see Using Waypoints in Routes below.)
204 | * alternatives — If set to true, specifies that the Directions service may provide more than one route alternative in the response. Note that providing route alternatives may increase the response time from the server.
205 | * avoid — Indicates that the calculated route(s) should avoid the indicated features. This parameter supports the following arguments:
206 | * tolls indicates that the calculated route should avoid toll roads/bridges.
207 | * highways indicates that the calculated route should avoid highways.
208 | * ferries indicates that the calculated route should avoid ferries.
209 | * For more information see Route Restrictions below.
210 | * language — The language in which to return results. See the list of supported domain languages. Note that we often update supported languages so this list may not be exhaustive. If language is not supplied, the service will attempt to use the native language of the domain from which the request is sent.
211 | * units — Specifies the unit system to use when displaying results. Valid values are specified in Unit Systems below.
212 | * region — The region code, specified as a ccTLD ("top-level domain") two-character value. (For more information see Region Biasing below.)
213 | * departure_time specifies the desired time of departure as seconds since midnight, January 1, 1970 UTC. The departure time may be specified in two cases:
214 | * For Transit Directions: One of departure_time or arrival_time must be specified when requesting directions.
215 | * For Driving Directions: Google Maps API for Work customers can specify the departure_time to receive trip duration considering current traffic conditions. The departure_time must be set to within a few minutes of the current time.
216 | * A special departure_time value "now" can also be used to automatically calculate the current departure time. Note that a numeric departure_time must be specified as an integer.
217 | * arrival_time specifies the desired time of arrival for transit directions as seconds since midnight, January 1, 1970 UTC. One of departure_time or arrival_time must be specified when requesting transit directions. Note that arrival_time must be specified as an integer.
218 | * Either the arrival_time or the departure_time parameter must be specified any time you request transit directions.
219 | *
220 | * @goals
221 | * This class aims to make an async call to the server and retrieve the Json representing
222 | * the Direction
223 | * Then build the GDirection object
224 | * Then post it to the DCACallBack in the UI Thread
225 | */
226 | public static final class GoogleDirectionAsyncRestCall extends AsyncTask> {
227 |
228 |
229 | /**
230 | * The CallBack which waiting for the GDirection object
231 | */
232 | private DCACallBack callback;
233 |
234 | /**
235 | * @param callback
236 | * The callBack waiting for the GDirection Object
237 | * @param data
238 | * data for request
239 | */
240 | public GoogleDirectionAsyncRestCall(DCACallBack callback) {
241 | super();
242 |
243 | this.callback = callback;
244 | }
245 |
246 | /*
247 | * (non-Javadoc)
248 | *
249 | * @see android.os.AsyncTask#doInBackground(java.lang.Object[])
250 | */
251 | @Override
252 | protected List doInBackground(GDirectionData... arg0) {
253 | // Do the rest http call
254 | String json = Util.getJSONDirection(arg0[0]);
255 | // Parse the element and return it
256 | return Util.parseJsonGDir(json);
257 | }
258 |
259 | /*
260 | * (non-Javadoc)
261 | *
262 | * @see android.os.AsyncTask#onPostExecute(java.lang.Object)
263 | */
264 | @Override
265 | protected void onPostExecute(List result) {
266 | super.onPostExecute(result);
267 | // Just call the callback
268 | callback.onDirectionLoaded(result);
269 | }
270 | }
271 |
272 | }
273 |
--------------------------------------------------------------------------------
/GDirectionsApiUtils/src/com/android2ee/formation/librairies/google/map/utils/direction/IGDFormatter.java:
--------------------------------------------------------------------------------
1 | package com.android2ee.formation.librairies.google.map.utils.direction;
2 |
3 | import com.android2ee.formation.librairies.google.map.utils.direction.model.GDLegs;
4 | import com.android2ee.formation.librairies.google.map.utils.direction.model.GDPath;
5 | import com.android2ee.formation.librairies.google.map.utils.direction.model.GDirection;
6 | import com.google.android.gms.maps.model.Marker;
7 |
8 | /**
9 | * @author florian
10 | * Interface between client and method drawGDirection
11 | * Can custom the display of infoWindows, or just change title and snippet
12 | */
13 | public interface IGDFormatter {
14 |
15 | /**
16 | * Method to get the title of this path
17 | * @param path, the current path which display on maps
18 | * @return the title of this path
19 | */
20 | public abstract String getTitle(GDPath path);
21 |
22 | /**
23 | * Method to get the string in snippet to display of this path
24 | * @param path, the current path which display on maps
25 | * @return the snippet string of this path
26 | */
27 | public abstract String getSnippet(GDPath path);
28 |
29 | /**
30 | * is a info windows or not ?
31 | * for custom snippet it will be true, else true
32 | * @return yes or no
33 | */
34 | public abstract boolean isInfoWindows();
35 |
36 | /**
37 | * Display custom snippet if isInfoWindows is true
38 | * Construct your custom view here
39 | * @param marker, the current marker
40 | * @param direction, the current direction
41 | * @param legs, the current legs
42 | * @param path, the current path
43 | */
44 | public abstract void setContents(Marker marker,GDirection direction, GDLegs legs, GDPath path);
45 | }
46 |
--------------------------------------------------------------------------------
/GDirectionsApiUtils/src/com/android2ee/formation/librairies/google/map/utils/direction/model/GDColor.java:
--------------------------------------------------------------------------------
1 | package com.android2ee.formation.librairies.google.map.utils.direction.model;
2 |
3 |
4 | /**
5 | * @author florian
6 | * Class GDColor
7 | * contains the color of path and pin for the api
8 | *
9 | */
10 | public class GDColor {
11 |
12 | /**
13 | * value for the color of path (int) resource
14 | */
15 | public Integer colorLine;
16 | /**
17 | * value for the color of pin (float) BitmapDescriptorFactory.X
18 | */
19 | public Float colorPin;
20 |
21 |
22 | /**
23 | * Constructor of GDColor
24 | * @param colorLine : the color of path
25 | * @param colorPin : color of pin
26 | */
27 | public GDColor(Integer colorLine, Float colorPin) {
28 | super();
29 | this.colorLine = colorLine;
30 | this.colorPin = colorPin;
31 | };
32 |
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/GDirectionsApiUtils/src/com/android2ee/formation/librairies/google/map/utils/direction/model/GDLegs.java:
--------------------------------------------------------------------------------
1 | /**
2 | * - GoogleMapSample
3 | * - com.android2ee.formation.librairies.google.map.utils.direction.model
4 | * - 13 sept. 2013
5 | *
6 | * - ======================================================
7 | *
8 | * - Projet : Mathias Seguy Project
9 | * - Produit par MSE.
10 | *
11 | /**
12 | *
13 | * Android Tutorial, An Android2EE's project.
14 | * Produced by Dr. Mathias SEGUY.
15 | * Delivered by http://android2ee.com/
16 | * Belongs to Mathias Seguy
17 | ****************************************************************************************************************
18 | * This code is free for any usage except training and can't be distribute.
19 | * The distribution is reserved to the site http://android2ee.com.
20 | * The intelectual property belongs to Mathias Seguy.
21 | * http://mathias-seguy.developpez.com/
22 | *
23 | * *****************************************************************************************************************
24 | * Ce code est libre de toute utilisation mais n'est pas distribuable.
25 | * Sa distribution est reservée au site http://android2ee.com.
26 | * Sa propriété intellectuelle appartient à Mathias Seguy.
27 | * http://mathias-seguy.developpez.com/
28 | * *****************************************************************************************************************
29 | */
30 | package com.android2ee.formation.librairies.google.map.utils.direction.model;
31 |
32 | import java.util.List;
33 |
34 | /**
35 | * @author Mathias Seguy (Android2EE)
36 | * @goals
37 | * This class aims to describes a GoogleDirection Legs which is bound to the JSon structure
38 | * returned by the webService :
39 | * "http://maps.googleapis.com/maps/api/directions/json?" + "origin=" + start.latitude + ","
40 | * + start.longitude + "&destination=" + end.latitude + "," + end.longitude
41 | * + "&sensor=false&units=metric&mode=driving";
42 | */
43 | public class GDLegs {
44 | /**
45 | * A GDLegs is a list of GDPath
46 | */
47 | List mPathsList;
48 | /**
49 | * The distance of the leg
50 | */
51 | int mDistance;
52 | /**
53 | * The duration of the leg
54 | */
55 | int mDuration;
56 | /**
57 | * Starting address
58 | */
59 | String mStartAddress;
60 | /**
61 | * Ending Address
62 | */
63 | String mEndAddress;
64 |
65 | /**
66 | * @param pathsList
67 | */
68 | public GDLegs(List pathsList) {
69 | super();
70 | this.mPathsList = pathsList;
71 | }
72 |
73 | /**
74 | * @return the mLegsList
75 | */
76 | public final List getPathsList() {
77 | return mPathsList;
78 | }
79 |
80 | /**
81 | * @param mLegsList the mLegsList to set
82 | */
83 | public final void setPathsList(List mPathsList) {
84 | this.mPathsList = mPathsList;
85 | }
86 |
87 | /**
88 | * @return the mDistance
89 | */
90 | public final int getmDistance() {
91 | return mDistance;
92 | }
93 |
94 | /**
95 | * @param mDistance the mDistance to set
96 | */
97 | public final void setmDistance(int mDistance) {
98 | this.mDistance = mDistance;
99 | }
100 |
101 | /**
102 | * @return the mDuration
103 | */
104 | public final int getmDuration() {
105 | return mDuration;
106 | }
107 |
108 | /**
109 | * @param mDuration the mDuration to set
110 | */
111 | public final void setmDuration(int mDuration) {
112 | this.mDuration = mDuration;
113 | }
114 |
115 | /**
116 | * @return the mStartAddress
117 | */
118 | public final String getmStartAddress() {
119 | return mStartAddress;
120 | }
121 |
122 | /**
123 | * @param mStartAddress the mStartAddress to set
124 | */
125 | public final void setmStartAddress(String mStartAddress) {
126 | this.mStartAddress = mStartAddress;
127 | }
128 |
129 | /**
130 | * @return the mEndAddress
131 | */
132 | public final String getmEndAddress() {
133 | return mEndAddress;
134 | }
135 |
136 | /**
137 | * @param mEndAddress the mEndAddress to set
138 | */
139 | public final void setmEndAddress(String mEndAddress) {
140 | this.mEndAddress = mEndAddress;
141 | }
142 |
143 | /* (non-Javadoc)
144 | * @see java.lang.Object#toString()
145 | */
146 | @Override
147 | public String toString() {
148 | StringBuilder strB=new StringBuilder("GLegs\r\n");
149 | for(GDPath path:mPathsList) {
150 | strB.append(path.toString());
151 | strB.append("\r\n");
152 | }
153 | return strB.toString();
154 | }
155 | }
156 |
--------------------------------------------------------------------------------
/GDirectionsApiUtils/src/com/android2ee/formation/librairies/google/map/utils/direction/model/GDPath.java:
--------------------------------------------------------------------------------
1 | /**
2 | * - GoogleMapSample
3 | * - com.android2ee.formation.librairies.google.map.utils.direction.model
4 | * - 13 sept. 2013
5 | *
6 | * - ======================================================
7 | *
8 | * - Projet : Mathias Seguy Project
9 | * - Produit par MSE.
10 | *
11 | /**
12 | *
13 | * Android Tutorial, An Android2EE's project.
14 | * Produced by Dr. Mathias SEGUY.
15 | * Delivered by http://android2ee.com/
16 | * Belongs to Mathias Seguy
17 | ****************************************************************************************************************
18 | * This code is free for any usage except training and can't be distribute.
19 | * The distribution is reserved to the site http://android2ee.com.
20 | * The intelectual property belongs to Mathias Seguy.
21 | * http://mathias-seguy.developpez.com/
22 | *
23 | * *****************************************************************************************************************
24 | * Ce code est libre de toute utilisation mais n'est pas distribuable.
25 | * Sa distribution est reservée au site http://android2ee.com.
26 | * Sa propriété intellectuelle appartient à Mathias Seguy.
27 | * http://mathias-seguy.developpez.com/
28 | * *****************************************************************************************************************
29 | */
30 | package com.android2ee.formation.librairies.google.map.utils.direction.model;
31 |
32 | import java.util.List;
33 |
34 | /**
35 | * @author Mathias Seguy (Android2EE)
36 | * @goals
37 | * This class aims toThis class aims to define a GoogleDirection Path which is bound to the JSon structure
38 | * returned by the webService :
39 | * "http://maps.googleapis.com/maps/api/directions/json?" + "origin=" + start.latitude + ","
40 | * + start.longitude + "&destination=" + end.latitude + "," + end.longitude
41 | * + "&sensor=false&units=metric&mode=driving";
42 | */
43 | public class GDPath {
44 | /**
45 | * A path is a list of GDPoints
46 | */
47 | List mPath;
48 | /**
49 | * The distance of the path
50 | */
51 | int mDistance;
52 | /**
53 | * The duration of the path
54 | */
55 | int mDuration;
56 | /**
57 | * The travel mode of the path
58 | */
59 | String mTravelMode;
60 | /**
61 | * The Html text associated with the path
62 | */
63 | String mHtmlText;
64 |
65 | /**
66 | * @param path The list of GDPoint that makes the path
67 | */
68 | public GDPath(List path) {
69 | super();
70 | this.mPath = path;
71 | }
72 |
73 | /**
74 | * @return the mPath
75 | */
76 | public final List getPath() {
77 | return mPath;
78 | }
79 |
80 | /**
81 | * @param mPath the mPath to set
82 | */
83 | public final void setPath(List mPath) {
84 | this.mPath = mPath;
85 | }
86 |
87 | /**
88 | * @return the mPath
89 | */
90 | public final List getmPath() {
91 | return mPath;
92 | }
93 |
94 | /**
95 | * @return the mDistance
96 | */
97 | public final int getDistance() {
98 | return mDistance;
99 | }
100 |
101 | /**
102 | * @return the mDuration
103 | */
104 | public final int getDuration() {
105 | return mDuration;
106 | }
107 |
108 | /**
109 | * @return the mTravelMode
110 | */
111 | public final String getTravelMode() {
112 | return mTravelMode;
113 | }
114 |
115 | /**
116 | * @return the mHtmlText
117 | */
118 | public final String getHtmlText() {
119 | return mHtmlText;
120 | }
121 |
122 | /**
123 | * @param mPath the mPath to set
124 | */
125 | public final void setmPath(List mPath) {
126 | this.mPath = mPath;
127 | }
128 |
129 | /**
130 | * @param mDistance the mDistance to set
131 | */
132 | public final void setDistance(int distance) {
133 | this.mDistance = distance;
134 | }
135 |
136 | /**
137 | * @param mDuration the mDuration to set
138 | */
139 | public final void setDuration(int duration) {
140 | this.mDuration = duration;
141 | }
142 |
143 | /**
144 | * @param mTravelMode the mTravelMode to set
145 | */
146 | public final void setTravelMode(String travelMode) {
147 | this.mTravelMode = travelMode;
148 | }
149 |
150 | /**
151 | * @param mHtmlText the mHtmlText to set
152 | */
153 | public final void setHtmlText(String htmlText) {
154 | this.mHtmlText = htmlText;
155 | }
156 |
157 | /* (non-Javadoc)
158 | * @see java.lang.Object#toString()
159 | */
160 | @Override
161 | public String toString() {
162 | StringBuilder strB=new StringBuilder("GPath\r\n");
163 | for(GDPoint point:mPath) {
164 | strB.append(point.toString());
165 | strB.append(point.toString());
166 | strB.append(",");
167 | }
168 | return strB.toString();
169 | }
170 |
171 | }
172 |
--------------------------------------------------------------------------------
/GDirectionsApiUtils/src/com/android2ee/formation/librairies/google/map/utils/direction/model/GDPoint.java:
--------------------------------------------------------------------------------
1 | /**
2 | * - GoogleMapSample
3 | * - com.android2ee.formation.librairies.google.map.utils.direction.model
4 | * - 13 sept. 2013
5 | *
6 | * - ======================================================
7 | *
8 | * - Projet : Mathias Seguy Project
9 | * - Produit par MSE.
10 | *
11 | /**
12 | *
13 | * Android Tutorial, An Android2EE's project.
14 | * Produced by Dr. Mathias SEGUY.
15 | * Delivered by http://android2ee.com/
16 | * Belongs to Mathias Seguy
17 | ****************************************************************************************************************
18 | * This code is free for any usage except training and can't be distribute.
19 | * The distribution is reserved to the site http://android2ee.com.
20 | * The intelectual property belongs to Mathias Seguy.
21 | * http://mathias-seguy.developpez.com/
22 | *
23 | * *****************************************************************************************************************
24 | * Ce code est libre de toute utilisation mais n'est pas distribuable.
25 | * Sa distribution est reservée au site http://android2ee.com.
26 | * Sa propriété intellectuelle appartient à Mathias Seguy.
27 | * http://mathias-seguy.developpez.com/
28 | * *****************************************************************************************************************
29 | */
30 | package com.android2ee.formation.librairies.google.map.utils.direction.model;
31 |
32 | import com.google.android.gms.maps.model.LatLng;
33 |
34 | /**
35 | * @author Mathias Seguy (Android2EE)
36 | * @goals
37 | * This class aims to define a GoogleDirection Point which is bound to the JSon structure
38 | * returned by the webService :
39 | * "http://maps.googleapis.com/maps/api/directions/json?" + "origin=" + start.latitude + ","
40 | * + start.longitude + "&destination=" + end.latitude + "," + end.longitude
41 | * + "&sensor=false&units=metric&mode=driving";
42 | */
43 | public class GDPoint {
44 | double mLat;
45 | double mLng;
46 | /**
47 | * The corresponding LatLng
48 | * Not in the JSon Object. It's an helpful attribute
49 | */
50 | private LatLng mLatLng = null;
51 |
52 | /**
53 | * The builder
54 | * @param coordinate retrieve from JSon
55 | */
56 | public GDPoint(double lat,double lng) {
57 | super();
58 | this.mLat = lat;
59 | this.mLng=lng;
60 | }
61 |
62 | /**
63 | * @return The LatLng Object linked with that point
64 | */
65 | public LatLng getLatLng() {
66 | if (mLatLng == null) {
67 | mLatLng = new LatLng(mLat,mLng);
68 | }
69 | return mLatLng;
70 | }
71 |
72 | /* (non-Javadoc)
73 | * @see java.lang.Object#toString()
74 | */
75 | @Override
76 | public String toString() {
77 | return "["+mLat+","+mLng+"]";
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/GDirectionsApiUtils/src/com/android2ee/formation/librairies/google/map/utils/direction/model/GDirection.java:
--------------------------------------------------------------------------------
1 | /**
2 | * - GoogleMapSample
3 | * - com.android2ee.formation.librairies.google.map.utils.direction
4 | * - 12 sept. 2013
5 | *
6 | * - ======================================================
7 | *
8 | * - Projet : Mathias Seguy Project
9 | * - Produit par MSE.
10 | *
11 | /**
12 | *
13 | * Android Tutorial, An Android2EE's project.
14 | * Produced by Dr. Mathias SEGUY.
15 | * Delivered by http://android2ee.com/
16 | * Belongs to Mathias Seguy
17 | ****************************************************************************************************************
18 | * This code is free for any usage except training and can't be distribute.
19 | * The distribution is reserved to the site http://android2ee.com.
20 | * The intelectual property belongs to Mathias Seguy.
21 | * http://mathias-seguy.developpez.com/
22 | *
23 | * *****************************************************************************************************************
24 | * Ce code est libre de toute utilisation mais n'est pas distribuable.
25 | * Sa distribution est reservée au site http://android2ee.com.
26 | * Sa propriété intellectuelle appartient à Mathias Seguy.
27 | * http://mathias-seguy.developpez.com/
28 | * *****************************************************************************************************************
29 | */
30 | package com.android2ee.formation.librairies.google.map.utils.direction.model;
31 |
32 | import java.util.List;
33 |
34 | import com.google.android.gms.maps.model.LatLng;
35 |
36 | /**
37 | * @author Mathias Seguy (Android2EE)
38 | * @goals
39 | * This class aims to define a GoogleDirection which is bound to the JSon structure
40 | * returned by the webService :
41 | * "http://maps.googleapis.com/maps/api/directions/json?" + "origin=" + start.latitude + ","
42 | * + start.longitude + "&destination=" + end.latitude + "," + end.longitude
43 | * + "&sensor=false&units=metric&mode=driving";
44 | */
45 | public class GDirection {
46 | /**
47 | * A GDirection is a list of GDLegs
48 | */
49 | List mLegsList;
50 | /**
51 | * The North East corner of the square enclosing the road
52 | */
53 | LatLng mNorthEastBound;
54 | /**
55 | * The South West corner of the square enclosing the road
56 | */
57 | LatLng mSouthWestBound;
58 | /**
59 | * Copyrights
60 | */
61 | String copyrights;
62 |
63 | /**
64 | * @param pathsList
65 | */
66 | public GDirection(List legsList) {
67 | super();
68 | this.mLegsList = legsList;
69 | }
70 |
71 | /**
72 | * @return the mPathsList
73 | */
74 | public final List getLegsList() {
75 | return mLegsList;
76 | }
77 |
78 | /**
79 | * @param mPathsList
80 | * the mPathsList to set
81 | */
82 | public final void setPathsList(List mLegsList) {
83 | this.mLegsList = mLegsList;
84 | }
85 |
86 | /**
87 | * @return the mNorthEastBound
88 | */
89 | public final LatLng getmNorthEastBound() {
90 | return mNorthEastBound;
91 | }
92 |
93 | /**
94 | * @param mNorthEastBound the mNorthEastBound to set
95 | */
96 | public final void setmNorthEastBound(LatLng mNorthEastBound) {
97 | this.mNorthEastBound = mNorthEastBound;
98 | }
99 |
100 | /**
101 | * @return the mSouthWestBound
102 | */
103 | public final LatLng getmSouthWestBound() {
104 | return mSouthWestBound;
105 | }
106 |
107 | /**
108 | * @param mSouthWestBound the mSouthWestBound to set
109 | */
110 | public final void setmSouthWestBound(LatLng mSouthWestBound) {
111 | this.mSouthWestBound = mSouthWestBound;
112 | }
113 | /**
114 | * @return the copyrights
115 | */
116 | public final String getCopyrights() {
117 | return copyrights;
118 | }
119 |
120 | /**
121 | * @param copyrights the copyrights to set
122 | */
123 | public final void setCopyrights(String copyrights) {
124 | this.copyrights = copyrights;
125 | }
126 | /*
127 | * (non-Javadoc)
128 | *
129 | * @see java.lang.Object#toString()
130 | */
131 | @Override
132 | public String toString() {
133 | StringBuilder strB = new StringBuilder("GDirection\r\n");
134 | for (GDLegs path : mLegsList) {
135 | strB.append(path.toString());
136 | strB.append("\r\n");
137 | }
138 | return strB.toString();
139 | }
140 |
141 | }
142 |
--------------------------------------------------------------------------------
/GDirectionsApiUtils/src/com/android2ee/formation/librairies/google/map/utils/direction/parser/DirectionsJSONParser.java:
--------------------------------------------------------------------------------
1 | package com.android2ee.formation.librairies.google.map.utils.direction.parser;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | import org.json.JSONArray;
7 | import org.json.JSONException;
8 | import org.json.JSONObject;
9 |
10 | import android.util.Log;
11 |
12 | import com.android2ee.formation.librairies.google.map.utils.direction.model.GDLegs;
13 | import com.android2ee.formation.librairies.google.map.utils.direction.model.GDPath;
14 | import com.android2ee.formation.librairies.google.map.utils.direction.model.GDPoint;
15 | import com.android2ee.formation.librairies.google.map.utils.direction.model.GDirection;
16 | import com.google.android.gms.maps.model.LatLng;
17 |
18 | //http://wptrafficanalyzer.in/blog/author/george/
19 | /**
20 | * @author Mathias Seguy (Android2EE)
21 | * @goals
22 | * This class aims to parse a json object like that:
23 | * {
24 | "routes" : [
25 | {
26 | "bounds" : {
27 | "northeast" : {
28 | "lat" : 50.63918229999999,
29 | "lng" : 3.0378181
30 | },
31 | "southwest" : {
32 | "lat" : 50.6359351,
33 | "lng" : 3.027635
34 | }
35 | },
36 | "copyrights" : "Données cartographiques ©2014 Google",
37 | "legs" : [
38 | {
39 | "distance" : {
40 | "text" : "1,0 km",
41 | "value" : 1022
42 | },
43 | "duration" : {
44 | "text" : "13 minutes",
45 | "value" : 761
46 | },
47 | "end_address" : "D751, 59000 Lille, France",
48 | "end_location" : {
49 | "lat" : 50.6362271,
50 | "lng" : 3.0378181
51 | },
52 | "start_address" : "1-5 D933, 59130 Lambersart, France",
53 | "start_location" : {
54 | "lat" : 50.6359351,
55 | "lng" : 3.027635
56 | },
57 | "steps" : [
58 | {
59 | "distance" : {
60 | "text" : "0,5 km",
61 | "value" : 535
62 | },
63 | "duration" : {
64 | "text" : "6 minutes",
65 | "value" : 383
66 | },
67 | "end_location" : {
68 | "lat" : 50.63918229999999,
69 | "lng" : 3.0331989
70 | },
71 | "html_instructions" : "Prendre la direction \u003cb\u003enord-est\u003c/b\u003e sur \u003cb\u003eAv. du Colisée/D933\u003c/b\u003e vers \u003cb\u003eRésidence le Clos du Colissee\u003c/b\u003e\u003cdiv style=\"font-size:0.9em\"\u003eContinuer de suivre Av. du Colisée\u003c/div\u003e",
72 | "polyline" : {
73 | "points" : "sy`tHwinQCOEKGOEMCEOc@GSS_@g@y@S_@KMEQWc@i@eACIk@sAa@{@a@{@k@iAS_@MQGIQWYa@KQS_@k@gA}@gB[s@CKOc@"
74 | },
75 | "start_location" : {
76 | "lat" : 50.6359351,
77 | "lng" : 3.027635
78 | },
79 | "travel_mode" : "WALKING"
80 | },
81 | {
82 | "distance" : {
83 | "text" : "0,5 km",
84 | "value" : 487
85 | },
86 | "duration" : {
87 | "text" : "6 minutes",
88 | "value" : 378
89 | },
90 | "end_location" : {
91 | "lat" : 50.6362271,
92 | "lng" : 3.0378181
93 | },
94 | "html_instructions" : "Prendre \u003cb\u003eà droite\u003c/b\u003e sur \u003cb\u003eAv. de l'Hippodrome/D751\u003c/b\u003e\u003cdiv style=\"font-size:0.9em\"\u003eContinuer de suivre D751\u003c/div\u003e\u003cdiv style=\"font-size:0.9em\"\u003eVotre destination se trouvera sur la droite\u003c/div\u003e",
95 | "maneuver" : "turn-right",
96 | "polyline" : {
97 | "points" : "{matHoloQLKb@]JILQDEDCROFGBAHIROJIJILMLIDENMp@_@vAgARWJMPWLUP[HSHUFSFYDQBUFS@IHc@BK?CLw@@APgA@IN{@?E@GTwA"
98 | },
99 | "start_location" : {
100 | "lat" : 50.63918229999999,
101 | "lng" : 3.0331989
102 | },
103 | "travel_mode" : "WALKING"
104 | }
105 | ],
106 | "via_waypoint" : []
107 | }
108 | ],
109 | "overview_polyline" : {
110 | "points" : "sy`tHwinQQk@a@kA{AgCkAeCmAoCmAeCa@q@Ya@e@s@_AgByA{CSo@p@i@X[f@a@tAgATSp@_@vAgA^e@^m@Zo@Pi@XuAr@iEf@aD"
111 | },
112 | "summary" : "Av. du Colisée et D751",
113 | "warnings" : [
114 | "Le calcul d'itinéraires piétons est en bêta. Faites attention – Cet itinéraire n'est peut-être pas complètement aménagé pour les piétons."
115 | ],
116 | "waypoint_order" : []
117 | }
118 | ],
119 | "status" : "OK"
120 | }
121 | */
122 | public class DirectionsJSONParser {
123 | String tag = "DirectionsJSONParser";
124 |
125 | /**
126 | * Receives a JSONObject and returns a GDirection
127 | *
128 | * @param jObject
129 | * The Json to parse
130 | * @return The GDirection defined by the JSon Object
131 | */
132 | public List parse(JSONObject jObject) {
133 | // The returned direction
134 | List directionsList = null;
135 | // The current GDirection
136 | GDirection currentGDirection = null;
137 | // The legs
138 | List legs = null;
139 | // The current leg
140 | GDLegs currentLeg = null;
141 | // The paths
142 | List paths = null;
143 | // The current path
144 | GDPath currentPath = null;
145 | // JSON Array representing Routes
146 | JSONArray jRoutes = null;
147 | JSONObject jRoute;
148 | JSONObject jBound;
149 | // JSON Array representing Legs
150 | JSONArray jLegs = null;
151 | JSONObject jLeg;
152 | // JSON Array representing Step
153 | JSONArray jSteps = null;
154 | JSONObject jStep;
155 | String polyline = "";
156 | try {
157 | jRoutes = jObject.getJSONArray("routes");
158 | Log.v(tag, "routes found : " + jRoutes.length());
159 | directionsList = new ArrayList();
160 | /** Traversing all routes */
161 | for (int i = 0; i < jRoutes.length(); i++) {
162 | jRoute=(JSONObject) jRoutes.get(i);
163 | jLegs = jRoute.getJSONArray("legs");
164 | Log.v(tag, "routes[" + i + "]contains jLegs found : " + jLegs.length());
165 | /** Traversing all legs */
166 | legs = new ArrayList();
167 | for (int j = 0; j < jLegs.length(); j++) {
168 | jLeg=(JSONObject) jLegs.get(j);
169 | jSteps = jLeg.getJSONArray("steps");
170 | Log.v(tag, "routes[" + i + "]:legs[" + j + "] contains jSteps found : " + jSteps.length());
171 | /** Traversing all steps */
172 | paths = new ArrayList();
173 | for (int k = 0; k < jSteps.length(); k++) {
174 | jStep = (JSONObject) jSteps.get(k);
175 | polyline = (String) ((JSONObject) (jStep).get("polyline")).get("points");
176 | // Build the List of GDPoint that define the path
177 | List list = decodePoly(polyline);
178 | // Create the GDPath
179 | currentPath = new GDPath(list);
180 | currentPath.setDistance(((JSONObject)jStep.get("distance")).getInt("value"));
181 | currentPath.setDuration(((JSONObject)jStep.get("duration")).getInt("value"));
182 | currentPath.setHtmlText(jStep.getString("html_instructions"));
183 | currentPath.setTravelMode(jStep.getString("travel_mode"));
184 | Log.v(tag,
185 | "routes[" + i + "]:legs[" + j + "]:Step[" + k + "] contains Points found : "
186 | + list.size());
187 | // Add it to the list of Path of the Direction
188 | paths.add(currentPath);
189 | }
190 | //
191 | currentLeg = new GDLegs(paths);
192 | currentLeg.setmDistance(((JSONObject)jLeg.get("distance")).getInt("value"));
193 | currentLeg.setmDuration(((JSONObject)jLeg.get("duration")).getInt("value"));
194 | currentLeg.setmEndAddress(jLeg.getString("end_address"));
195 | currentLeg.setmStartAddress(jLeg.getString("start_address"));
196 | legs.add(currentLeg);
197 |
198 | Log.v(tag, "Added a new Path and paths size is : " + paths.size());
199 | }
200 | // Build the GDirection using the paths found
201 | currentGDirection = new GDirection(legs);
202 | jBound=(JSONObject)jRoute.get("bounds");
203 | currentGDirection.setmNorthEastBound(new LatLng(
204 | ((JSONObject)jBound.get("northeast")).getDouble("lat"),
205 | ((JSONObject)jBound.get("northeast")).getDouble("lng")));
206 | currentGDirection.setmSouthWestBound(new LatLng(
207 | ((JSONObject)jBound.get("southwest")).getDouble("lat"),
208 | ((JSONObject)jBound.get("southwest")).getDouble("lng")));
209 | currentGDirection.setCopyrights(jRoute.getString("copyrights"));
210 | directionsList.add(currentGDirection);
211 | }
212 |
213 | } catch (JSONException e) {
214 | Log.e(tag, "Parsing JSon from GoogleDirection Api failed, see stack trace below:", e);
215 | } catch (Exception e) {
216 | Log.e(tag, "Parsing JSon from GoogleDirection Api failed, see stack trace below:", e);
217 | }
218 | return directionsList;
219 | }
220 |
221 | /**
222 | * Method to decode polyline points
223 | * Courtesy :
224 | * http://jeffreysambells.com/2010/05/27/decoding-polylines-from-google-maps-direction
225 | * -api-with-java
226 | */
227 | private List decodePoly(String encoded) {
228 |
229 | List poly = new ArrayList();
230 | int index = 0, len = encoded.length();
231 | int lat = 0, lng = 0;
232 |
233 | while (index < len) {
234 | int b, shift = 0, result = 0;
235 | do {
236 | b = encoded.charAt(index++) - 63;
237 | result |= (b & 0x1f) << shift;
238 | shift += 5;
239 | } while (b >= 0x20);
240 | int dlat = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1));
241 | lat += dlat;
242 |
243 | shift = 0;
244 | result = 0;
245 | do {
246 | b = encoded.charAt(index++) - 63;
247 | result |= (b & 0x1f) << shift;
248 | shift += 5;
249 | } while (b >= 0x20);
250 | int dlng = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1));
251 | lng += dlng;
252 | poly.add(new GDPoint((double) lat / 1E5, (double) lng / 1E5));
253 | }
254 |
255 | return poly;
256 | }
257 | }
--------------------------------------------------------------------------------
/GDirectionsApiUtils/src/com/android2ee/formation/librairies/google/map/utils/direction/util/Avoid.java:
--------------------------------------------------------------------------------
1 | package com.android2ee.formation.librairies.google.map.utils.direction.util;
2 |
3 | /**
4 | * @author florian
5 | * Enum of parameter Avoid
6 | * HIGHWAYS, FERRIES, TOLLS possible
7 | */
8 | public enum Avoid {
9 |
10 | AVOID_HIGHWAYS("highways"),
11 | AVOID_FERRIES("ferries"),
12 | AVOID_TOLLS("tolls");
13 |
14 | /**
15 | * contains value in string of enum
16 | */
17 | private final String name;
18 |
19 | /**
20 | * Constructor of enum with string value in parameter
21 | * @param s
22 | */
23 | private Avoid(String s) {
24 | name = s;
25 | }
26 |
27 | /**
28 | * Compare two Avoid
29 | * @param otherName
30 | * @return if same or not
31 | */
32 | public boolean equalsName(String otherName){
33 | return (otherName == null)? false:name.equals(otherName);
34 | }
35 |
36 | /**
37 | * @return string value
38 | */
39 | public String toString() {
40 | return name;
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/GDirectionsApiUtils/src/com/android2ee/formation/librairies/google/map/utils/direction/util/GDirectionData.java:
--------------------------------------------------------------------------------
1 | package com.android2ee.formation.librairies.google.map.utils.direction.util;
2 |
3 | import com.google.android.gms.maps.model.LatLng;
4 |
5 | /**
6 | *
7 | * @param mode
8 | * The direction mode (driving,walking...)
9 | * @param waypoints
10 | * The waypoints
11 | * @param alternative
12 | * alternatives routes
13 | * @param avoid
14 | * avoid route type ( highways, tolls, ferries)
15 | * @param language
16 | * The language (fr, es, ...) need language code here
17 | * @param us
18 | * The unit system (metric , imperial)
19 | * @param region
20 | * The region (fr, es, ...) need country code here
21 | * @param departure time
22 | * the departure time only if we are in transit or driving mode
23 | * @param arrival time
24 | * The arrival time wanted, only if we are in transit mode
25 | **/
26 |
27 | public class GDirectionData {
28 |
29 | /**
30 | * start position to the request
31 | */
32 | LatLng start;
33 | /**
34 | * end position to the request
35 | */
36 | LatLng end;
37 | /**
38 | * mode The direction mode (driving,walking...)
39 | */
40 | Mode mode;
41 | /**
42 | * waypoints, The waypoints do you want for the request
43 | */
44 | String waypoints;
45 | /**
46 | * alternative, alternatives routes ?
47 | */
48 | boolean alternative;
49 | /**
50 | * avoid, avoid route type ( highways, tolls, ferries)
51 | */
52 | Avoid avoid;
53 | /**
54 | * language The language (fr, es, ...) need language code here
55 | */
56 | String language;
57 | /**
58 | * us, The unit system (metric , imperial)
59 | */
60 | UnitSystem us;
61 | /**
62 | * region, The region (fr, es, ...) need country code here
63 | */
64 | String region;
65 | /**
66 | * departure_time, the departure time only if we are in transit or driving mode
67 | */
68 | String departure_time;
69 | /**
70 | * arrival_time, The arrival time wanted, only if we are in transit mode
71 | */
72 | String arrival_time;
73 |
74 |
75 | /**
76 | * Constructor private, we can just build this class by the Builder
77 | * must have a startPoint and endPoint
78 | * @param start
79 | * the start position
80 | * @param end
81 | * the end position
82 | */
83 | private GDirectionData(LatLng start, LatLng end) {
84 | super();
85 | this.start = start;
86 | this.end = end;
87 | }
88 |
89 | /**
90 | * Get start position
91 | * @return start Position
92 | */
93 | public LatLng getStart() {
94 | return start;
95 | }
96 |
97 | /**
98 | * Get end position
99 | * @return end position
100 | */
101 | public LatLng getEnd() {
102 | return end;
103 | }
104 |
105 | /**
106 | * Get mode
107 | * @return mode
108 | */
109 | public Mode getMode() {
110 | return mode;
111 | }
112 |
113 | /**
114 | * get waypoints
115 | * @return waypoints
116 | */
117 | public String getWaypoints() {
118 | return waypoints;
119 | }
120 |
121 | /**
122 | * Get alternative route
123 | * @return alternative
124 | */
125 | public boolean isAlternative() {
126 | return alternative;
127 | }
128 |
129 | /**
130 | * Get avoid
131 | * @return avoid
132 | */
133 | public Avoid getAvoid() {
134 | return avoid;
135 | }
136 |
137 | /**
138 | * Get language
139 | * @return language
140 | */
141 | public String getLanguage() {
142 | return language;
143 | }
144 |
145 | /**
146 | * Get unit system
147 | * @return unit system
148 | */
149 | public UnitSystem getUs() {
150 | return us;
151 | }
152 |
153 | /**
154 | * Get region
155 | * @return region
156 | */
157 | public String getRegion() {
158 | return region;
159 | }
160 |
161 | /**
162 | * Get departure_time
163 | * @return departure_time
164 | */
165 | public String getDeparture_time() {
166 | return departure_time;
167 | }
168 |
169 | /**
170 | * Get arrival_time
171 | * @return arrival_time
172 | */
173 | public String getArrival_time() {
174 | return arrival_time;
175 | }
176 |
177 | /**
178 | * Builder
179 | * @author florian
180 | *
181 | */
182 | public static class Builder {
183 | /**
184 | * start position
185 | */
186 | LatLng start;
187 | /**
188 | * end position
189 | */
190 | LatLng end;
191 | /**
192 | * mode The direction mode (driving,walking...)
193 | */
194 | Mode mode;
195 | /**
196 | * waypoints, The waypoints do you want for the request
197 | */
198 | String waypoints;
199 | /**
200 | * alternative, alternatives routes ?
201 | */
202 | boolean alternative;
203 | /**
204 | * avoid, avoid route type ( highways, tolls, ferries)
205 | */
206 | Avoid avoid;
207 | /**
208 | * language, language type fr, es, etc.
209 | */
210 | String language;
211 | /**
212 | * us, The unit system (metric , imperial)
213 | */
214 | UnitSystem us;
215 | /**
216 | * Region, region type fr, es, etc.
217 | */
218 | String region;
219 |
220 | /**
221 | * Constructor of the Builder, required start at end always
222 | * @param start
223 | * start position
224 | * @param end
225 | * end position
226 | */
227 | public Builder(LatLng start, LatLng end) {
228 | super();
229 | this.start = start;
230 | this.end = end;
231 |
232 | this.mode = null;
233 | this.waypoints = null;
234 | this.alternative = false;
235 | this.avoid = null;
236 | this.language = null;
237 | this.us = null;
238 | this.region = null;
239 | }
240 |
241 | /**
242 | * Get start position
243 | * @return start position
244 | */
245 | public LatLng getStart() {
246 | return start;
247 | }
248 |
249 | /**
250 | * Get end position
251 | * @return end position
252 | */
253 | public LatLng getEnd() {
254 | return end;
255 | }
256 |
257 | /**
258 | * Get mode
259 | * @return mode
260 | */
261 | public Mode getMode() {
262 | return mode;
263 | }
264 |
265 | /**
266 | * Set Mode
267 | * @param mode
268 | * @return builder
269 | */
270 | public Builder setMode(Mode mode) {
271 | this.mode = mode;
272 | return this;
273 | }
274 |
275 | /**
276 | * Get waypoints
277 | * @return waypoints
278 | */
279 | public String getWaypoints() {
280 | return waypoints;
281 | }
282 |
283 | /**
284 | * Set waypoints
285 | * @param waypoints
286 | * @return builder
287 | */
288 | public Builder setWaypoints(String waypoints) {
289 | this.waypoints = waypoints;
290 | return this;
291 | }
292 |
293 | /**
294 | * Get alternative
295 | * @return alternative
296 | */
297 | public boolean isAlternative() {
298 | return alternative;
299 | }
300 |
301 | /**
302 | * Set Alternatives
303 | * @param alternative
304 | * @return builder
305 | */
306 | public Builder setAlternative(boolean alternative) {
307 | this.alternative = alternative;
308 | return this;
309 | }
310 |
311 | /**
312 | * Get avoid
313 | * @return avoid
314 | */
315 | public Avoid getAvoid() {
316 | return avoid;
317 | }
318 |
319 | /**
320 | * Set Avoid
321 | * @param avoid
322 | * @return builder
323 | */
324 | public Builder setAvoid(Avoid avoid) {
325 | this.avoid = avoid;
326 | return this;
327 | }
328 |
329 | /**
330 | * Get language
331 | * @return language
332 | */
333 | public String getLanguage() {
334 | return language;
335 | }
336 |
337 | /**
338 | * Set language
339 | * @param language
340 | * @return builder
341 | */
342 | public Builder setLanguage(String language) {
343 | this.language = language;
344 | return this;
345 | }
346 |
347 | /**
348 | * Get unit system
349 | * @return unit system
350 | */
351 | public UnitSystem getUs() {
352 | return us;
353 | }
354 |
355 | /**
356 | * Set unit system
357 | * @param us
358 | * @return builder
359 | */
360 | public Builder setUs(UnitSystem us) {
361 | this.us = us;
362 | return this;
363 | }
364 |
365 | /**
366 | * Get region
367 | * @return region
368 | */
369 | public String getRegion() {
370 | return region;
371 | }
372 |
373 | /**
374 | * Set region
375 | * @param region
376 | * @return builder
377 | */
378 | public Builder setRegion(String region) {
379 | this.region = region;
380 | return this;
381 | }
382 |
383 | /**
384 | * Build method, need to construct data to request gDirection of Google
385 | * @return GDirectionData
386 | */
387 | public GDirectionData build() {
388 | // create object
389 | GDirectionData result = new GDirectionData(start, end);
390 | // insert parameters given
391 | result.mode = mode;
392 | result.waypoints = waypoints;
393 | result.alternative = alternative;
394 | result.avoid = avoid;
395 | result.language = language;
396 | result.us = us;
397 | result.region = region;
398 | result.departure_time = null;
399 | result.arrival_time = null;
400 | return result;
401 | }
402 |
403 | }
404 |
405 | /**
406 | * Creator :)
407 | * @author florian
408 | *
409 | */
410 | public abstract static class Creator {
411 |
412 | public Builder mBuilder;
413 |
414 | public void setBuilder(Builder builder) {
415 | if (mBuilder != builder) {
416 | mBuilder = builder;
417 | }
418 | }
419 |
420 | /**
421 | * Check if Builder present else throw an error
422 | */
423 | protected void checkBuilder() {
424 | if (mBuilder == null) {
425 | throw new IllegalArgumentException("Creator requires a valid Builder object");
426 | }
427 | }
428 |
429 | public abstract GDirectionData build();
430 |
431 | }
432 |
433 | /**
434 | * DepartureCreator
435 | * @author florian
436 | *
437 | */
438 | public static class DepartureCreator extends Creator {
439 |
440 | String departure_time;
441 |
442 | public DepartureCreator() {
443 | }
444 |
445 | public DepartureCreator(Builder builder) {
446 | setBuilder(builder);
447 | }
448 |
449 | public String getDeparture_time() {
450 | return departure_time;
451 | }
452 |
453 | public DepartureCreator setDeparture_time(String departure_time) {
454 | this.departure_time = departure_time;
455 | return this;
456 | }
457 |
458 | @Override
459 | public GDirectionData build() {
460 | checkBuilder();
461 | if (mBuilder.getMode() != Mode.MODE_TRANSIT && mBuilder.getMode() != Mode.MODE_DRIVING) {
462 | throw new IllegalArgumentException("Mode is not correct requires a Transit/Driving mode for the DepartureCreator");
463 | }
464 | GDirectionData data = mBuilder.build();
465 | data.departure_time = departure_time;
466 | return data;
467 | }
468 |
469 |
470 | }
471 |
472 | /**
473 | * TransitCreator
474 | * @author florian
475 | *
476 | */
477 | public static class TansitCreator extends Creator {
478 |
479 | String departure_time;
480 | String arrival_time;
481 |
482 | public TansitCreator() {
483 | }
484 |
485 | public TansitCreator(Builder builder) {
486 | setBuilder(builder);
487 | }
488 |
489 | public String getDeparture_time() {
490 | return departure_time;
491 | }
492 |
493 | public TansitCreator setDeparture_time(String departure_time) {
494 | this.departure_time = departure_time;
495 | return this;
496 | }
497 |
498 | public String getArrival_time() {
499 | return arrival_time;
500 | }
501 |
502 | public TansitCreator setArrival_time(String arrival_time) {
503 | this.arrival_time = arrival_time;
504 | return this;
505 | }
506 |
507 | @Override
508 | public GDirectionData build() {
509 | checkBuilder();
510 | if (mBuilder.getMode() == Mode.MODE_TRANSIT) {
511 | throw new IllegalArgumentException("Mode is not correct requires a Transit mode for the TransitCreator");
512 | }
513 | GDirectionData data = mBuilder.build();
514 | data.departure_time = departure_time;
515 | data.arrival_time = arrival_time;
516 | return data;
517 | }
518 | }
519 |
520 | }
521 |
--------------------------------------------------------------------------------
/GDirectionsApiUtils/src/com/android2ee/formation/librairies/google/map/utils/direction/util/GDirectionMapsOptions.java:
--------------------------------------------------------------------------------
1 | package com.android2ee.formation.librairies.google.map.utils.direction.util;
2 |
3 | import java.util.ArrayList;
4 |
5 | import com.android2ee.formation.librairies.google.map.utils.direction.IGDFormatter;
6 | import com.android2ee.formation.librairies.google.map.utils.direction.model.GDColor;
7 | import com.google.android.gms.maps.model.PolylineOptions;
8 |
9 | /**
10 | *
11 | * @param formatter
12 | * formatter, to know how to display the snippet on a marker
13 | * @param colors (GDColor)
14 | * The colors of line and marker
15 | * @param polylineoptions
16 | * polyline options
17 | **/
18 |
19 | public class GDirectionMapsOptions {
20 |
21 | /**
22 | * formatter snippet
23 | */
24 | IGDFormatter formatter;
25 | /**
26 | * colors marker and line
27 | */
28 | ArrayList colors;
29 | /**
30 | * line options
31 | */
32 | PolylineOptions polylineOptions;
33 |
34 | /**
35 | * Constructor private, we can just build this class by the Builder
36 | */
37 | private GDirectionMapsOptions() {
38 | super();
39 |
40 | }
41 |
42 |
43 | /**
44 | * get Formatter
45 | * @return formatter
46 | */
47 | public IGDFormatter getFormatter() {
48 | return formatter;
49 | }
50 |
51 | /**
52 | * Set Formatter
53 | * @param formatter
54 | */
55 | public void setFormatter(IGDFormatter formatter) {
56 | this.formatter = formatter;
57 | }
58 |
59 | /**
60 | * Get Colors
61 | * @return colors
62 | */
63 | public ArrayList getColors() {
64 | return colors;
65 | }
66 |
67 | /**
68 | * Set Colors
69 | * @param colors
70 | */
71 | public void setColors(ArrayList colors) {
72 | this.colors = colors;
73 | }
74 |
75 | /**
76 | * Get PolylineOption
77 | * @return poylineOptions
78 | */
79 | public PolylineOptions getPolylineOptions() {
80 | return polylineOptions;
81 | }
82 |
83 | /**
84 | * Set PolylineOption
85 | * @param polylineOptions
86 | */
87 | public void setPolylineOptions(PolylineOptions polylineOptions) {
88 | this.polylineOptions = polylineOptions;
89 | }
90 |
91 |
92 |
93 | /**
94 | * Builder
95 | * @author florian
96 | *
97 | */
98 | public static class Builder {
99 |
100 | /**
101 | * formatter snippet
102 | */
103 | IGDFormatter formatter;
104 | /**
105 | * colors marker and line
106 | */
107 | ArrayList colors;
108 | /**
109 | * line options
110 | */
111 | PolylineOptions polylineOptions;
112 |
113 | /**
114 | * Constructor of the Builder
115 | */
116 | public Builder() {
117 | super();
118 |
119 | this.formatter = null;
120 | this.colors = null;
121 | this.polylineOptions = null;
122 | }
123 |
124 | /**
125 | * Get formatter
126 | * @return formatter
127 | */
128 | public IGDFormatter getFormatter() {
129 | return formatter;
130 | }
131 |
132 | /**
133 | * Set Formatter
134 | * @param formatter
135 | * @return builder
136 | */
137 | public Builder setFormatter(IGDFormatter formatter) {
138 | this.formatter = formatter;
139 | return this;
140 | }
141 |
142 | /**
143 | * Get colors
144 | * @return colors
145 | */
146 | public ArrayList getColors() {
147 | return colors;
148 | }
149 |
150 | /**
151 | * Set Colors
152 | * @param colors
153 | * @return builder
154 | */
155 | public Builder setColors(ArrayList colors) {
156 | this.colors = colors;
157 | return this;
158 | }
159 |
160 | /**
161 | * Set Colors
162 | * @param color , add one color
163 | * @return builder
164 | */
165 | public Builder setColor(GDColor color) {
166 | this.colors = new ArrayList<>();
167 | this.colors.add(color);
168 | return this;
169 | }
170 |
171 | /**
172 | * Get PolylineOption
173 | * @return polylineOptions
174 | */
175 | public PolylineOptions getPolylineOptions() {
176 | return polylineOptions;
177 | }
178 |
179 | /**
180 | * Set PolylineOptions
181 | * @param polylineOptions
182 | * @return builder
183 | */
184 | public Builder setPolylineOptions(PolylineOptions polylineOptions) {
185 | this.polylineOptions = polylineOptions;
186 | return this;
187 | }
188 |
189 |
190 | /**
191 | * Build method, need to construct data to request gDirection of Google
192 | * @return GDirectionData
193 | */
194 | public GDirectionMapsOptions build() {
195 | // create object
196 | GDirectionMapsOptions result = new GDirectionMapsOptions();
197 | // insert parameters given
198 | result.formatter = formatter;
199 | result.colors = colors;
200 | result.polylineOptions = polylineOptions;
201 | return result;
202 | }
203 |
204 | }
205 |
206 | /**
207 | * Creator :)
208 | * @author florian
209 | *
210 | */
211 | public abstract static class Creator {
212 |
213 | public Builder mBuilder;
214 |
215 | public void setBuilder(Builder builder) {
216 | if (mBuilder != builder) {
217 | mBuilder = builder;
218 | }
219 | }
220 |
221 | /**
222 | * Check if Builder present else throw an error
223 | */
224 | protected void checkBuilder() {
225 | if (mBuilder == null) {
226 | throw new IllegalArgumentException("Creator requires a valid Builder object");
227 | }
228 | }
229 |
230 | public abstract GDirectionMapsOptions build();
231 |
232 | }
233 |
234 | }
235 |
--------------------------------------------------------------------------------
/GDirectionsApiUtils/src/com/android2ee/formation/librairies/google/map/utils/direction/util/Mode.java:
--------------------------------------------------------------------------------
1 | package com.android2ee.formation.librairies.google.map.utils.direction.util;
2 |
3 | /**
4 | * @author florian
5 | * Mode enum
6 | * DRIVING, WALKING, BICYCLING, TRANSIT
7 | *
8 | */
9 | public enum Mode {
10 |
11 | MODE_DRIVING("driving"),
12 | MODE_WALKING("walking"),
13 | MODE_BICYCLING("bicycling"),
14 | MODE_TRANSIT("transit");
15 |
16 | /**
17 | * contains value in string of enum
18 | */
19 | private final String name;
20 |
21 | /**
22 | * Constructor of enum
23 | * @param s, string value
24 | */
25 | private Mode(String s) {
26 | name = s;
27 | }
28 |
29 | /**
30 | * Compare two Mode
31 | * @param otherName
32 | * @return if same or not
33 | */
34 | public boolean equalsName(String otherName){
35 | return (otherName == null)? false:name.equals(otherName);
36 | }
37 |
38 | /**
39 | * @return string value
40 | */
41 | public String toString(){
42 | return name;
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/GDirectionsApiUtils/src/com/android2ee/formation/librairies/google/map/utils/direction/util/UnitSystem.java:
--------------------------------------------------------------------------------
1 | package com.android2ee.formation.librairies.google.map.utils.direction.util;
2 |
3 | /**
4 | * @author florian
5 | * Unit System enum
6 | * METRIC, IMPERIAL
7 | *
8 | */
9 | public enum UnitSystem {
10 |
11 | US_METRIC("metric"),
12 | US_IMPERIAL("imperial");
13 |
14 | /**
15 | * contains value in string of enum
16 | */
17 | private final String name;
18 |
19 | /**
20 | * Constructor
21 | * @param s, the string value
22 | */
23 | private UnitSystem(String s) {
24 | name = s;
25 | }
26 |
27 | /**
28 | * Compare two UnitSystem
29 | * @param otherName
30 | * @return if same or not
31 | */
32 | public boolean equalsName(String otherName){
33 | return (otherName == null)? false:name.equals(otherName);
34 | }
35 |
36 | /**
37 | * @return string value
38 | */
39 | public String toString(){
40 | return name;
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/GDirectionsApiUtils/src/com/android2ee/formation/librairies/google/map/utils/direction/util/Util.java:
--------------------------------------------------------------------------------
1 | package com.android2ee.formation.librairies.google.map.utils.direction.util;
2 |
3 | import java.io.IOException;
4 | import java.util.ArrayList;
5 | import java.util.List;
6 |
7 | import org.apache.http.client.ClientProtocolException;
8 | import org.apache.http.client.HttpClient;
9 | import org.apache.http.client.ResponseHandler;
10 | import org.apache.http.client.methods.HttpGet;
11 | import org.apache.http.impl.client.BasicResponseHandler;
12 | import org.apache.http.impl.client.DefaultHttpClient;
13 | import org.json.JSONObject;
14 |
15 | import android.util.Log;
16 |
17 | import com.android2ee.formation.librairies.google.map.utils.direction.model.GDirection;
18 | import com.android2ee.formation.librairies.google.map.utils.direction.parser.DirectionsJSONParser;
19 |
20 | /**
21 | * @author florian
22 | * Class Util
23 | * contains all method useful for GDirectionApi
24 | *
25 | */
26 | public class Util {
27 |
28 | /**
29 | * Simple Rest Call to the Google Direction WebService
30 | * http://maps.googleapis.com/maps/api/directions/json?
31 | *
32 | * @param data
33 | * data to parse
34 | * @return The json returned by the webServer
35 | */
36 | public static String getJSONDirection(GDirectionData data) {
37 | String url = "http://maps.googleapis.com/maps/api/directions/json?" + "origin=" + data.getStart().latitude + ","
38 | + data.getStart().longitude + "&destination=" + data.getEnd().latitude + "," + data.getEnd().longitude
39 | + "&sensor=false";
40 |
41 |
42 | /**
43 | * mode
44 | */
45 | if (data.getMode() != null) {
46 | url += "&mode=" + data.getMode();
47 | }
48 |
49 | /**
50 | * waypoints
51 | */
52 | if (data.getWaypoints() != null) {
53 | url += "&waypoints=" + data.getWaypoints();
54 | }
55 |
56 | /**
57 | * alternative
58 | */
59 | url += "&alternatives=" + data.isAlternative();
60 |
61 | /**
62 | * avoid
63 | */
64 | if (data.getAvoid() != null) {
65 | url += "&avoid=" + data.getAvoid();
66 | }
67 |
68 | /**
69 | * language
70 | */
71 | if (data.getLanguage() != null) {
72 | url += "&language=" + data.getLanguage();
73 | }
74 |
75 | /**
76 | * units
77 | */
78 | if (data.getUs() != null) {
79 | url += "&units=" + data.getUs();
80 | }
81 |
82 | /**
83 | * region
84 | */
85 | if (data.getRegion() != null) {
86 | url += "®ion=" + data.getRegion();
87 | }
88 |
89 | /**
90 | * units
91 | */
92 | if (data.getDeparture_time() != null && data.getMode() != null && (data.getMode() == Mode.MODE_DRIVING || data.getMode() == Mode.MODE_TRANSIT)) {
93 | url += "&departure_time=" + data.getDeparture_time();
94 | }
95 |
96 | /**
97 | * region
98 | */
99 | if (data.getArrival_time() != null && data.getMode() != null && data.getMode() == Mode.MODE_TRANSIT) {
100 | url += "&arrival_time=" + data.getArrival_time();
101 | }
102 |
103 | String responseBody = null;
104 | // The HTTP get method send to the URL
105 | HttpGet getMethod = new HttpGet(url);
106 | // The basic response handler
107 | ResponseHandler responseHandler = new BasicResponseHandler();
108 | // instantiate the http communication
109 | HttpClient client = new DefaultHttpClient();
110 | // Call the URL and get the response body
111 | try {
112 | responseBody = client.execute(getMethod, responseHandler);
113 | } catch (ClientProtocolException e) {
114 | Log.e(Util.class.getCanonicalName(), e.getMessage());
115 | } catch (IOException e) {
116 | Log.e(Util.class.getCanonicalName(), e.getMessage());
117 | }
118 | if (responseBody != null) {
119 | Log.e(Util.class.getCanonicalName(), responseBody);
120 | }
121 | // parse the response body
122 | return responseBody;
123 | }
124 |
125 | /**
126 | * Parse the Json to build the GDirection object associated
127 | *
128 | * @param json
129 | * The Json to parse
130 | * @return The GDirection define by the JSon
131 | */
132 | public static List parseJsonGDir(String json) {
133 | // JSon Object to parse
134 | JSONObject jObject;
135 | // The GDirection to return
136 | List directions = null;
137 | if (json != null) {
138 | try {
139 | // initialize the JSon
140 | jObject = new JSONObject(json);
141 | // initialize the parser
142 | DirectionsJSONParser parser = new DirectionsJSONParser();
143 | // Starts parsing data
144 | directions = parser.parse(jObject);
145 | } catch (Exception e) {
146 | Log.e(Util.class.getCanonicalName(), "Parsing JSon from GoogleDirection Api failed, see stack trace below:", e);
147 | }
148 | } else {
149 | directions = new ArrayList();
150 | }
151 | return directions;
152 | }
153 | }
154 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | GDirectionsApiUtils
2 | ===================
3 |
4 | This project aims to simplify the usage of the Google Map Direction Rest Api
5 | This project is done to help you using the Google Rest Api Direction : http://maps.googleapis.com/maps/api/directions/json?
6 |
7 | How it works, definitly simply. You download the jar (gdirectionsapiutils.jar under GDirectionsApiUtils\bin\ ) in the libs folder of your application (under bin) and use it:
8 | ```JAVA
9 |
10 | public class MainActivity extends ActionBarActivity implements DCACallBack{
11 | /**
12 | * Get the Google Direction between mDevice location and the touched location using the Walk
13 | * @param point
14 | */
15 | private void getDirections(LatLng startPoint, LatLng endPoint) {
16 | GDirectionData.Builder builder = new GDirectionData.Builder(startPoint, endPoint)
17 | .setMode(Mode.MODE_DRIVING)
18 | .setAlternative(true)
19 | .setAvoid(Avoid.AVOID_HIGHWAYS)
20 | .setLanguage("fr")
21 | .setUs(UnitSystem.US_METRIC);
22 | GDirectionData data = new GDirectionData.DepartureCreator(builder)
23 | .setDeparture_time("now")
24 | .build();
25 | GDirectionsApiUtils.getDirection(this, data);
26 | }
27 |
28 | /*
29 | * The callback
30 | * When the direction is built from the google server and parsed, this method is called and give you the expected direction
31 | */
32 | @Override
33 | public void onDirectionLoaded(List directions) {
34 | ArrayList colors = new ArrayList();
35 | colors.add(new GDColor(Color.BLACK, BitmapDescriptorFactory.HUE_VIOLET));
36 | colors.add(new GDColor(Color.BLUE, BitmapDescriptorFactory.HUE_AZURE));
37 | colors.add(new GDColor(Color.YELLOW, BitmapDescriptorFactory.HUE_YELLOW));
38 | colors.add(new GDColor(Color.CYAN, BitmapDescriptorFactory.HUE_CYAN));
39 | int MAX_COLOR = colors.size();
40 |
41 |
42 | for(int i = 0; i < directions.size(); i ++) {
43 | ArrayList colors = new ArrayList();
44 | colors.add(colorsDirection.get(i % MAX_COLOR));
45 |
46 |
47 | GDirectionMapsOptions.Builder builder = new GDirectionMapsOptions.Builder()
48 | .setColors(colors)
49 | .setPolylineOptions(new PolylineOptions().width(10).zIndex(5));
50 |
51 | GDirectionMapsOptions mapOptions = builder.build();
52 |
53 | GDirectionsApiUtils.drawGDirection(directions.get(i), map, mapOptions);
54 | }
55 | }
56 | ```
57 |
58 | ## Snippet
59 |
60 | ### Snippet Simple
61 |
62 | To add comment which you want in snippet, you just have to add a formatter when you build your GDirectionMapsOptions
63 |
64 | ```JAVA
65 | GDirectionMapsOptions.Builder builder = new GDirectionMapsOptions.Builder()
66 | .setColors(colors)
67 | .setPolylineOptions(new PolylineOptions().width(10).zIndex(5))
68 | .setFormatter(new FormatterSimple());
69 |
70 | GDirectionMapsOptions mapOptions = builder.build();
71 | ```
72 |
73 | And implements this class
74 |
75 | ```JAVA
76 | public class FormatterSimple implements IGDFormatter {
77 |
78 | @Override
79 | public String getTitle(GDPath path) {
80 | return "Distance :" + path.getDistance();
81 | }
82 |
83 | @Override
84 | public String getSnippet(GDPath path) {
85 | return Html.fromHtml(path.getHtmlText()).toString();
86 | }
87 |
88 | @Override
89 | public boolean isInfoWindows() {
90 | return false;
91 | }
92 |
93 | @Override
94 | public void setContents(Marker marker, GDirection direction,
95 | GDLegs legs, GDPath path) {
96 | }
97 | };
98 | ```
99 |
100 |
101 | ### Custom Snippet
102 |
103 | If you want a custom layout for snippet cause you don't like the basic, you can customize this layout by add this code when you get the map :
104 |
105 | ```JAVA
106 | map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))
107 | .getMap();
108 | map.setInfoWindowAdapter(new InfoWindowAdapter() {
109 |
110 | @Override
111 | public View getInfoWindow(Marker marker) {
112 | View view = getLayoutInflater().inflate(R.layout.custom_view, null, false);
113 |
114 | // get data associate with the marker id in hash map, here a GDPath, see below
115 | GDPath path = hashMap.get(marker.getId());
116 | // TODO implement code here
117 | return view;
118 | }
119 |
120 | @Override
121 | public View getInfoContents(Marker marker) {
122 | return null;
123 | }
124 | });
125 |
126 | ```
127 |
128 | **Info** : you can keep the bubble and replace only the info window contents inside the default info window frame (the callout bubble), return null in getInfoWindow(Marker) and override getInfoContents(Marker) instead.
129 |
130 | And build your GDirectionMapsOptions with a new formatter
131 |
132 | ```JAVA
133 | GDirectionMapsOptions.Builder builder = new GDirectionMapsOptions.Builder()
134 | .setColors(colors)
135 | .setPolylineOptions(new PolylineOptions().width(10).zIndex(5).color(Color.BLUE))
136 | .setFormatter(new FormatterComplex());
137 |
138 | GDirectionMapsOptions mapOptions = builder.build();
139 | ```
140 |
141 | Next implements this class
142 |
143 | ```JAVA
144 | public class FormatterComplex implements IGDFormatter {
145 |
146 | @Override
147 | public String getTitle(GDPath path) {
148 | return "Distance :" + path.getDistance();
149 | }
150 |
151 | @Override
152 | public String getSnippet(GDPath path) {
153 | return Html.fromHtml(path.getHtmlText()).toString();
154 | }
155 |
156 | @Override
157 | public boolean isInfoWindows() {
158 | // here the information that we want customize the layout
159 | return true;
160 | }
161 |
162 | @Override
163 | public void setContents(Marker marker, GDirection direction,
164 | GDLegs legs, GDPath path) {
165 | // put the data associate with the marker id
166 | hashMap.put(marker.getId(), path);
167 | }
168 | };
169 | ```
170 |
--------------------------------------------------------------------------------