/[zanavi_public1]/navit/navit/android/src/com/zoffcc/applications/zanavi/NavitVehicle.java
ZANavi

Contents of /navit/navit/android/src/com/zoffcc/applications/zanavi/NavitVehicle.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 41 - (show annotations) (download)
Tue Aug 11 18:50:37 2015 UTC (8 years, 7 months ago) by zoff99
File size: 40832 byte(s)
many fixes, and new features
1 /**
2 * ZANavi, Zoff Android Navigation system.
3 * Copyright (C) 2011 - 2014 Zoff <zoff@zoff.cc>
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * version 2 as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19
20 /**
21 * Navit, a modular navigation system.
22 * Copyright (C) 2005-2008 Navit Team
23 *
24 * This program is free software; you can redistribute it and/or
25 * modify it under the terms of the GNU General Public License
26 * version 2 as published by the Free Software Foundation.
27 *
28 * This program is distributed in the hope that it will be useful,
29 * but WITHOUT ANY WARRANTY; without even the implied warranty of
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31 * GNU General Public License for more details.
32 *
33 * You should have received a copy of the GNU General Public License
34 * along with this program; if not, write to the
35 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
36 * Boston, MA 02110-1301, USA.
37 */
38
39 package com.zoffcc.applications.zanavi;
40
41 import java.io.BufferedWriter;
42 import java.io.File;
43 import java.io.FileWriter;
44 import java.text.DecimalFormat;
45 import java.text.DecimalFormatSymbols;
46 import java.text.SimpleDateFormat;
47 import java.util.Date;
48 import java.util.Iterator;
49 import java.util.Locale;
50
51 import android.content.Context;
52 import android.location.Criteria;
53 import android.location.GpsSatellite;
54 import android.location.GpsStatus;
55 import android.location.Location;
56 import android.location.LocationListener;
57 import android.location.LocationManager;
58 import android.location.LocationProvider;
59 import android.os.Bundle;
60 import android.os.Handler;
61 import android.os.Message;
62 import android.os.SystemClock;
63 import android.text.format.DateFormat;
64 import android.util.Log;
65
66 public class NavitVehicle
67 {
68 private LocationManager locationManager = null;
69 private static LocationManager locationManager_s = null;
70 private String preciseProvider = null;
71 private String fastProvider = null;
72 private static LocationListener fastLocationListener_s = null;
73 private static LocationListener preciseLocationListener_s = null;
74 private static GpsStatus.Listener gps_status_listener_s = null;
75 private static float compass_heading;
76 private static float current_accuracy = 99999999F;
77 private static long last_real_gps_update = -1;
78 static boolean sat_status_enabled = false;
79 static boolean sat_status_icon_updated = false;
80 static int sat_status_icon_last = -1;
81 static int sat_status_icon_now = -1;
82 static float gps_last_bearing = 0.0f;
83 static double gps_last_lat = 0.0d;
84 static double gps_last_lon = 0.0d;
85 static int gps_last_lat_1000 = 0;
86 static int gps_last_lon_1000 = 0;
87 static int fast_provider_status = 0;
88 static int disregard_first_fast_location = 0;
89
90 static long MILLIS_AFTER_GPS_FIX_IS_LOST = 2000;
91
92 static TunnelExtrapolationThread te_thread = null;
93
94 static boolean is_pos_recording = false;
95 static File pos_recording_file;
96 // static File pos_recording_file_gpx;
97 static File speech_recording_file_gpx;
98 static BufferedWriter pos_recording_writer;
99 // static BufferedWriter pos_recording_writer_gpx;
100 static BufferedWriter speech_recording_writer_gpx;
101 static boolean speech_recording_started = false;
102 // DateFormat sdf = new DateFormat();
103
104 int sats1_old = -1;
105 int satsInFix1_old = -1;
106
107 public static Handler vehicle_handler_ = null;
108 public static long lastcompass_update_timestamp = 0L;
109
110 public static final float GPS_SPEED_ABOVE_USE_FOR_HEADING = (float) (9 / 3.6f); // (9 km/h) / (3.6) ~= m/s
111
112 private static String preciseProvider_s = null;
113 static String fastProvider_s = null;
114
115 public static long last_p_fix = 0;
116 public static long last_f_fix = 0;
117 public Bundle gps_extras = null;
118 public static GpsStatus gps_status = null;
119 public static Boolean update_location_in_progress = false;
120
121 static long last_gps_status_update = 0L;
122
123 static DecimalFormat df2 = new DecimalFormat("#.####");
124
125 public static Location last_location = null;
126
127 public static native void VehicleCallback(double lat, double lon, float speed, float direction, double height, float radius, long gpstime);
128
129 public static void VehicleCallback2(Location location)
130 {
131 // if (Navit.METHOD_DEBUG) Navit.my_func_name(0);
132 String dd_text = "";
133
134 if (Navit.Global_Init_Finished != 0)
135 {
136 if (Navit.Global_Location_update_not_allowed == 0)
137 {
138 if (NavitGraphics.DEBUG_SMOOTH_DRIVING) System.out.println("DEBUG_SMOOTH_DRIVING:TMG-DEBUG:Gps");
139
140 // change bearing/direction to last good bearing -------------------
141 // change bearing/direction to last good bearing -------------------
142 // change bearing/direction to last good bearing -------------------
143 if ((location.getSpeed() < 5f) && (location.getBearing() == 0.0f) && (gps_last_bearing != 0.0f))
144 {
145 //if ((gps_last_lat_1000 == (int) (location.getLatitude() * 1000)) && (gps_last_lon_1000 == (int) (location.getLongitude() * 1000)))
146 //{
147 dd_text = dd_text + "a:";
148 location.setBearing(gps_last_bearing);
149 //}
150 }
151
152 if (location.getBearing() != 0.0f)
153 {
154 dd_text = dd_text + "n:";
155 gps_last_bearing = location.getBearing();
156 }
157 // change bearing/direction to last good bearing -------------------
158 // change bearing/direction to last good bearing -------------------
159 // change bearing/direction to last good bearing -------------------
160
161 if (Navit.p.PREF_enable_debug_write_gpx)
162 {
163 pos_recording_add(1, location.getLatitude(), location.getLongitude(), location.getSpeed(), location.getBearing(), location.getTime());
164 }
165
166 if (Navit.NAVIT_DEBUG_TEXT_VIEW) ZANaviOSDDebug01.add_text(dd_text + "b=" + location.getBearing() + " lb=" + gps_last_bearing);
167
168 Navit.cwthr.VehicleCallback3(location);
169 gps_last_lat = location.getLatitude();
170 gps_last_lon = location.getLongitude();
171 gps_last_lat_1000 = (int) (gps_last_lat * 1000);
172 gps_last_lon_1000 = (int) (gps_last_lon * 1000);
173 }
174 }
175 else
176 {
177 System.out.println("VehicleCallback2:Global_Init_Finished == 0 !!!!!!!");
178 }
179
180 // if (Navit.METHOD_DEBUG) Navit.my_func_name(1);
181
182 }
183
184 // private static SatStatusThread st = null;
185
186 private class SatStatusThread extends Thread
187 {
188 // get new gpsstatus --------
189 int sats1 = 0;
190 int satsInFix1 = 0;
191 Boolean running = true;
192
193 public void run()
194 {
195 this.running = true;
196
197 while (this.running)
198 {
199 try
200 {
201 if (!Navit.DemoVehicle)
202 {
203 GpsStatus stat = locationManager.getGpsStatus(gps_status);
204 gps_status = stat;
205 Iterator<GpsSatellite> localIterator = stat.getSatellites().iterator();
206 while (localIterator.hasNext())
207 {
208 GpsSatellite localGpsSatellite = (GpsSatellite) localIterator.next();
209 sats1++;
210 if (localGpsSatellite.usedInFix())
211 {
212 satsInFix1++;
213 }
214 }
215 }
216 }
217 catch (Exception e)
218 {
219 e.printStackTrace();
220 }
221 // System.out.println("Statellites (Thread): " + satsInFix1 + "/" + sats1);
222 // Navit.set_debug_messages3_wrapper("sat: " + satsInFix1 + "/" + sats1);
223 // get new gpsstatus --------
224
225 try
226 {
227 Thread.sleep(2000);
228 }
229 catch (InterruptedException e)
230 {
231 }
232 }
233 }
234
235 public void stop_me()
236 {
237 this.running = false;
238 }
239 }
240
241 NavitVehicle(Context context)
242 {
243 // ---------------------
244 // ---------------------
245 // ------- DEBUG: test #ifdef equivalent --------
246 // ---------------------
247 // final long ccccc = 2000000000L; // 2.000.000.000 (2 billion) iterations!
248 // // ---------------------
249 // final boolean flag1 = true;
250 // final boolean flag2 = false;
251 // // ---------------------
252 // long aa1 = System.currentTimeMillis();
253 // long j = 0;
254 // while (j < ccccc)
255 // {
256 // if (flag1)
257 // {
258 // if (flag2)
259 // {
260 // j++;
261 // }
262 // else
263 // {
264 // j++;
265 // }
266 // }
267 // }
268 // long aa2 = System.currentTimeMillis();
269 // System.out.println("NVVVVV:3a:" + ((float) (aa2 - aa1) / 1000f));
270 // // ---------------------
271 // boolean flag1b = true;
272 // boolean flag2b = false;
273 // // ---------------------
274 // aa1 = System.currentTimeMillis();
275 // j = 0;
276 // while (j < ccccc)
277 // {
278 // if (flag1b)
279 // {
280 // if (flag2b)
281 // {
282 // j++;
283 // }
284 // else
285 // {
286 // j++;
287 // }
288 // }
289 // }
290 // aa2 = System.currentTimeMillis();
291 // System.out.println("NVVVVV:3b:" + ((float) (aa2 - aa1) / 1000f));
292 // // ---------------------
293 // // ---------------------
294 // aa1 = System.currentTimeMillis();
295 // j = 0;
296 // while (j < ccccc)
297 // {
298 // j++;
299 // }
300 // aa2 = System.currentTimeMillis();
301 // System.out.println("NVVVVV:3c:" + ((float) (aa2 - aa1) / 1000f));
302 // ---------------------
303 // ---------------------
304 // ------- DEBUG test #ifdef equivalent --------
305 // ---------------------
306 // ---------------------
307
308 vehicle_handler_ = Navit.vehicle_handler;
309
310 locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
311 locationManager_s = locationManager;
312
313 LocationListener fastLocationListener = new LocationListener()
314 {
315 public void onLocationChanged(Location location)
316 {
317 if (disregard_first_fast_location > 0)
318 {
319 Log.e("NavitVehicle", "LocationChanged provider=fast" + " disregard_first_fast_location=" + disregard_first_fast_location);
320
321 disregard_first_fast_location--;
322 return;
323 }
324
325 last_f_fix = location.getTime();
326 // if last gps fix was longer than 8 secs. ago, use this fix
327 // and we dont have a GPS lock
328 if ((last_p_fix + 8000 < last_f_fix) && (Navit.satsInFix < 3))
329 {
330 if (Navit.p.PREF_follow_gps)
331 {
332 if (Navit.p.PREF_use_compass_heading_base)
333 {
334 if ((Navit.p.PREF_use_compass_heading_always) || (location.getSpeed() < GPS_SPEED_ABOVE_USE_FOR_HEADING))
335 {
336 // use compass heading
337 location.setBearing(compass_heading);
338 }
339 }
340
341 //System.out.println("send values 1");
342 // Log.e("NavitVehicle", "LocationChanged provider=fast Latitude " + location.getLatitude() + " Longitude " + location.getLongitude());
343 last_location = location;
344 if (!Navit.DemoVehicle)
345 {
346 //Log.e("NavitVehicle", "call VehicleCallback 001");
347 VehicleCallback2(location);
348 }
349 }
350 }
351 }
352
353 public void onProviderDisabled(String provider)
354 {
355 //Log.e("NavitVehicle", "onProviderDisabled -> provider=" + provider);
356 }
357
358 public void onProviderEnabled(String provider)
359 {
360 //Log.e("NavitVehicle", "onProviderEnabled -> provider=" + provider);
361 }
362
363 public void onStatusChanged(String provider, int status, Bundle extras)
364 {
365 //Log.e("NavitVehicle", "onStatusChanged -> provider=" + provider + " status=" + status);
366 try
367 {
368 switch (status)
369 {
370 case LocationProvider.OUT_OF_SERVICE:
371 System.out.println("*** No Service ***");
372 break;
373 case LocationProvider.TEMPORARILY_UNAVAILABLE:
374 System.out.println("*** No Fix ***");
375 break;
376 case LocationProvider.AVAILABLE:
377 System.out.println("@@@ Fix @@@");
378 break;
379 }
380 }
381 catch (Exception e)
382 {
383
384 }
385 }
386 };
387 fastLocationListener_s = fastLocationListener;
388
389 LocationListener preciseLocationListener = new LocationListener()
390 {
391 public void onLocationChanged(Location location)
392 {
393 last_p_fix = location.getTime();
394 current_accuracy = location.getAccuracy();
395
396 if (location != null)
397 {
398 Navit.mLastLocationMillis = SystemClock.elapsedRealtime();
399 Navit.mLastLocation = location;
400 }
401
402 if (Navit.p.PREF_follow_gps)
403 {
404 if (Navit.p.PREF_use_compass_heading_base)
405 {
406 if ((Navit.p.PREF_use_compass_heading_always) || (location.getSpeed() < GPS_SPEED_ABOVE_USE_FOR_HEADING))
407 {
408 // use compass heading
409 location.setBearing(compass_heading);
410 }
411 }
412 //System.out.println("send values 2");
413 //Log.e("NavitVehicle", "LocationChanged provider=precise Latitude " + location.getLatitude() + " Longitude " + location.getLongitude());
414 last_location = location;
415 //Log.e("NavitVehicle", "call VehicleCallback 002");
416 if (NavitGraphics.DEBUG_SMOOTH_DRIVING)
417 {
418 if (last_real_gps_update > -1)
419 {
420 Log.e("NavitVehicle", "gps-gap:" + (System.currentTimeMillis() - last_real_gps_update));
421 }
422 last_real_gps_update = System.currentTimeMillis();
423 }
424 VehicleCallback2(location);
425 }
426 }
427
428 public void onProviderDisabled(String provider)
429 {
430 //Log.e("NavitVehicle", "onProviderDisabled -> provider=" + provider);
431 }
432
433 public void onProviderEnabled(String provider)
434 {
435 //Log.e("NavitVehicle", "onProviderEnabled -> provider=" + provider);
436 }
437
438 public void onStatusChanged(String provider, int status, Bundle extras)
439 {
440 //Log.e("NavitVehicle", "onStatusChanged -> provider=" + provider + " status=" + status);
441
442 try
443 {
444 if (status == GpsStatus.GPS_EVENT_FIRST_FIX)
445 {
446 System.out.println("*** GPS first fix ***");
447 }
448 switch (status)
449 {
450 case LocationProvider.OUT_OF_SERVICE:
451 System.out.println("*** No Service ***");
452 break;
453 case LocationProvider.TEMPORARILY_UNAVAILABLE:
454 System.out.println("*** No Fix ***");
455 break;
456 case LocationProvider.AVAILABLE:
457 System.out.println("@@@ Fix @@@");
458 break;
459 }
460 }
461 catch (Exception e)
462 {
463
464 }
465 }
466 };
467 preciseLocationListener_s = preciseLocationListener;
468
469 /*
470 * Use 2 LocationProviders, one precise (usually GPS), and one
471 * not so precise, but possible faster.
472 */
473 Criteria highCriteria = null;
474 Criteria lowCriteria = null;
475 try
476 {
477 // Selection criterias for the precise provider
478 highCriteria = new Criteria();
479 highCriteria.setAccuracy(Criteria.ACCURACY_FINE);
480 highCriteria.setAltitudeRequired(false);
481 highCriteria.setBearingRequired(true);
482 //highCriteria.setCostAllowed(true);
483 //highCriteria.setPowerRequirement(Criteria.POWER_HIGH);
484
485 // Selection criterias for the fast provider
486 lowCriteria = new Criteria();
487 lowCriteria.setAccuracy(Criteria.ACCURACY_COARSE);
488 lowCriteria.setAltitudeRequired(false);
489 lowCriteria.setBearingRequired(false);
490 lowCriteria.setCostAllowed(true);
491 lowCriteria.setPowerRequirement(Criteria.POWER_LOW);
492 }
493 catch (Exception e)
494 {
495 e.printStackTrace();
496 }
497
498 try
499 {
500 Log.e("NavitVehicle", "Providers " + locationManager.getAllProviders());
501 //
502 preciseProvider = locationManager.getBestProvider(highCriteria, false);
503 preciseProvider_s = preciseProvider;
504 Log.e("NavitVehicle", "Precise Provider " + preciseProvider);
505 fastProvider = locationManager.getBestProvider(lowCriteria, false);
506 fastProvider_s = fastProvider;
507 Log.e("NavitVehicle", "Fast Provider " + fastProvider);
508 }
509 catch (Exception e)
510 {
511 e.printStackTrace();
512 }
513
514 try
515 {
516 //*in onresume()*// locationManager.requestLocationUpdates(preciseProvider, 0, 0, preciseLocationListener);
517 }
518 catch (Exception e)
519 {
520 e.printStackTrace();
521 }
522
523 try
524 {
525 // If the 2 providers are the same, only activate one listener
526 if (fastProvider == null || preciseProvider.compareTo(fastProvider) == 0)
527 {
528 fastProvider = null;
529 }
530 else
531 {
532 if (Navit.p.PREF_use_fast_provider)
533 {
534 //*in onresume()*//locationManager.requestLocationUpdates(fastProvider, 30000L, 8.0f, fastLocationListener); // (long)time [milliseconds], (float)minDistance [meters]
535 }
536 }
537 }
538 catch (Exception e)
539 {
540 e.printStackTrace();
541 }
542
543 gps_status_listener_s = new GpsStatus.Listener()
544 {
545 public void onGpsStatusChanged(int event)
546 {
547 if (event == GpsStatus.GPS_EVENT_SATELLITE_STATUS)
548 {
549
550 boolean old_fix = Navit.isGPSFix;
551 // ------------------------------
552 // thanks to: http://stackoverflow.com/questions/2021176/how-can-i-check-the-current-status-of-the-gps-receiver
553 // ------------------------------
554 if (Navit.mLastLocation != null)
555 {
556 Navit.isGPSFix = (SystemClock.elapsedRealtime() - Navit.mLastLocationMillis) < MILLIS_AFTER_GPS_FIX_IS_LOST;
557 }
558 // if (Navit.isGPSFix)
559 // {
560 // // A fix has been acquired.
561 // }
562 // else
563 // {
564 // // The fix has been lost.
565 // }
566 if (old_fix != Navit.isGPSFix)
567 {
568 try
569 {
570 Message msg = new Message();
571 Bundle b = new Bundle();
572 b.putInt("Callback", 102);
573 if (Navit.isGPSFix)
574 {
575 b.putString("s", "1");
576 }
577 else
578 {
579 b.putString("s", "0");
580 }
581 msg.setData(b);
582 NavitGraphics.callback_handler.sendMessage(msg);
583 }
584 catch (Exception e)
585 {
586 }
587
588 if (Navit.p.PREF_show_sat_status)
589 {
590 // redraw NavitOSDJava
591 // System.out.println("onDraw:show_sat_status:1");
592 NavitGraphics.OSD_new.postInvalidate();
593 }
594
595 if (Navit.want_tunnel_extrapolation())
596 {
597 turn_on_tunnel_extrapolation();
598 }
599 else
600 {
601 turn_off_tunnel_extrapolation();
602 }
603 }
604
605 // ------------------------------
606
607 if (last_gps_status_update + 4000 < System.currentTimeMillis())
608 {
609 last_gps_status_update = System.currentTimeMillis();
610
611 // get new gpsstatus --------
612
613 sats1_old = Navit.sats;
614 satsInFix1_old = Navit.satsInFix;
615
616 GpsStatus stat = locationManager.getGpsStatus(null);
617
618 Navit.sats = 0;
619 Navit.satsInFix = 0;
620
621 try
622 {
623 Iterator<GpsSatellite> localIterator = stat.getSatellites().iterator();
624 while (localIterator.hasNext())
625 {
626 GpsSatellite localGpsSatellite = (GpsSatellite) localIterator.next();
627 Navit.sats++;
628 if (localGpsSatellite.usedInFix())
629 {
630 Navit.satsInFix++;
631 }
632 }
633
634 // System.out.println("checking sat status update");
635
636 if ((sats1_old != Navit.sats) || (satsInFix1_old != Navit.satsInFix))
637 {
638 //System.out.println("sat status update -> changed");
639 if (Navit.p.PREF_show_sat_status)
640 {
641 // redraw NavitOSDJava
642 // System.out.println("onDraw:show_sat_status:2");
643 NavitGraphics.OSD_new.postInvalidate();
644 }
645 }
646 }
647 catch (Exception e)
648 {
649 e.printStackTrace();
650 }
651 }
652
653 // Navit.set_debug_messages3_wrapper("sat: " + Navit.satsInFix + "/" + Navit.sats);
654 // System.out.println("Statellites: " + Navit.satsInFix + "/" + Navit.sats);
655 // get new gpsstatus --------
656 }
657 else if (event == GpsStatus.GPS_EVENT_FIRST_FIX)
658 {
659 Navit.isGPSFix = true;
660 turn_off_tunnel_extrapolation();
661
662 try
663 {
664 Message msg = new Message();
665 Bundle b = new Bundle();
666 b.putInt("Callback", 102);
667 b.putString("s", "1");
668 msg.setData(b);
669 NavitGraphics.callback_handler.sendMessage(msg);
670 }
671 catch (Exception e)
672 {
673 }
674
675 if (Navit.p.PREF_show_sat_status)
676 {
677 // redraw NavitOSDJava
678 // System.out.println("onDraw:show_sat_status:3");
679 NavitGraphics.OSD_new.postInvalidate();
680 }
681 }
682 else if (event == GpsStatus.GPS_EVENT_STOPPED)
683 {
684 Navit.isGPSFix = false;
685
686 if (Navit.want_tunnel_extrapolation())
687 {
688 turn_on_tunnel_extrapolation();
689 }
690
691 try
692 {
693 Message msg = new Message();
694 Bundle b = new Bundle();
695 b.putInt("Callback", 102);
696 b.putString("s", "0");
697 msg.setData(b);
698 NavitGraphics.callback_handler.sendMessage(msg);
699 }
700 catch (Exception e)
701 {
702 }
703
704 if (Navit.p.PREF_show_sat_status)
705 {
706 // redraw NavitOSDJava
707 // System.out.println("onDraw:show_sat_status:4");
708 NavitGraphics.OSD_new.postInvalidate();
709 }
710 }
711 }
712 };
713
714 }
715
716 public static void set_mock_location__fast(Location mock_location)
717 {
718 float save_speed;
719
720 try
721 {
722 //locationManager_s.setTestProviderLocation("ZANavi_mock", mock_location);
723 // mock_location;
724 // System.out.println("llllllll" + mock_location.getLatitude() + " " + mock_location.getLongitude());
725 if (mock_location != null)
726 {
727 if (mock_location.getSpeed() == 0.0f)
728 {
729 if (last_location != null)
730 {
731 save_speed = last_location.getSpeed();
732 }
733 else
734 {
735 save_speed = 0.0f;
736 last_location = mock_location;
737 }
738 mock_location.setSpeed(0.2f);
739 //Log.e("NavitVehicle", "call VehicleCallback 003");
740 VehicleCallback2(mock_location);
741 mock_location.setSpeed(save_speed);
742 }
743 else
744 {
745 //Log.e("NavitVehicle", "call VehicleCallback 004");
746 VehicleCallback2(mock_location);
747 }
748 }
749 }
750 catch (Exception e)
751 {
752 e.printStackTrace();
753 }
754 }
755
756 public static void set_mock_location__fast_no_speed(Location mock_location)
757 {
758 try
759 {
760 //locationManager_s.setTestProviderLocation("ZANavi_mock", mock_location);
761 // mock_location;
762 // System.out.println("llllllll" + mock_location.getLatitude() + " " + mock_location.getLongitude());
763 if (mock_location != null)
764 {
765 //Log.e("NavitVehicle", "call VehicleCallback 004");
766 VehicleCallback2(mock_location);
767 }
768 }
769 catch (Exception e)
770 {
771 e.printStackTrace();
772 }
773 }
774
775 public static class location_coords
776 {
777 double lat;
778 double lon;
779 }
780
781 public static location_coords get_last_known_pos()
782 {
783 location_coords ret = new location_coords();
784
785 try
786 {
787 Location l = locationManager_s.getLastKnownLocation(preciseProvider_s);
788 if (l != null)
789 {
790 if (l.getAccuracy() > 0)
791 {
792 if ((l.getLatitude() != 0) && (l.getLongitude() != 0))
793 {
794 ret.lat = l.getLatitude();
795 ret.lon = l.getLongitude();
796 return ret;
797 }
798 }
799 }
800 }
801 catch (Exception e)
802 {
803 }
804
805 try
806 {
807 // If the 2 providers are the same, only activate one listener
808 if (fastProvider_s != null)
809 {
810 if (Navit.p.PREF_use_fast_provider)
811 {
812 if (!Navit.DemoVehicle)
813 {
814 Location l = locationManager_s.getLastKnownLocation(fastProvider_s);
815 //System.out.println("ZANAVI:getLastKnownLocation=" + l);
816 if (l != null)
817 {
818 if (l.getAccuracy() > 0)
819 {
820 if ((l.getLatitude() != 0) && (l.getLongitude() != 0))
821 {
822 ret.lat = l.getLatitude();
823 ret.lon = l.getLongitude();
824 return ret;
825 }
826 }
827 }
828 }
829 }
830 }
831 }
832 catch (Exception e)
833 {
834 }
835
836 return null;
837 }
838
839 public static void set_last_known_pos_precise_provider()
840 {
841 try
842 {
843 Location l = locationManager_s.getLastKnownLocation(preciseProvider_s);
844 if (l != null)
845 {
846 if (l.getAccuracy() > 0)
847 {
848 if ((l.getLatitude() != 0) && (l.getLongitude() != 0))
849 {
850 if (Navit.p.PREF_follow_gps)
851 {
852 // Log.e("NavitVehicle", "getLastKnownLocation precise (2) l=" + l.toString());
853 last_location = l;
854 //Log.e("NavitVehicle", "call VehicleCallback 005");
855 VehicleCallback2(l);
856 }
857 }
858 }
859 }
860 }
861 catch (Exception e)
862 {
863 e.printStackTrace();
864 }
865 }
866
867 public static void set_last_known_pos_fast_provider()
868 {
869 // System.out.println("fast_provider_status=" + fast_provider_status);
870
871 if (fast_provider_status == 0)
872 {
873 return;
874 }
875
876 try
877 {
878 // If the 2 providers are the same, only activate one listener
879 if (fastProvider_s != null)
880 {
881 if (Navit.p.PREF_use_fast_provider)
882 {
883 if (!Navit.DemoVehicle)
884 {
885 Location l = locationManager_s.getLastKnownLocation(fastProvider_s);
886 //System.out.println("ZANAVI:getLastKnownLocation=" + l);
887 if (l != null)
888 {
889 if (l.getAccuracy() > 0)
890 {
891 if ((l.getLatitude() != 0) && (l.getLongitude() != 0))
892 {
893 if (Navit.p.PREF_follow_gps)
894 {
895 // Log.e("NavitVehicle", "getLastKnownLocation fast (3) l=" + l.toString());
896 last_location = l;
897 //Log.e("NavitVehicle", "call VehicleCallback 006");
898 //System.out.println("ZANAVI:set_last_known_pos_fast_provider");
899 VehicleCallback2(l);
900 }
901 }
902 }
903 }
904 }
905 }
906 }
907 }
908 catch (Exception e)
909 {
910 e.printStackTrace();
911 }
912
913 }
914
915 public static void turn_on_fast_provider()
916 {
917 // if (Navit.METHOD_DEBUG) Navit.my_func_name(0);
918
919 try
920 {
921 // If the 2 providers are the same, only activate one listener
922 if (fastProvider_s != null)
923 {
924 if (Navit.p.PREF_use_fast_provider)
925 {
926 if (!Navit.DemoVehicle)
927 {
928 disregard_first_fast_location = 2;
929 locationManager_s.requestLocationUpdates(fastProvider_s, 30000L, 8.0f, fastLocationListener_s); // (long)time [milliseconds], (float)minDistance [meters]
930
931 fast_provider_status = 1;
932 //System.out.println("ZANAVI:turn on fast provider");
933 }
934 }
935 }
936 }
937 catch (Exception e)
938 {
939 e.printStackTrace();
940 }
941
942 // if (Navit.METHOD_DEBUG) Navit.my_func_name(1);
943 }
944
945 public static void turn_on_precise_provider()
946 {
947 // if (Navit.METHOD_DEBUG) Navit.my_func_name(0);
948
949 try
950 {
951 locationManager_s.requestLocationUpdates(preciseProvider_s, 0, 0, preciseLocationListener_s);
952 }
953 catch (Exception e)
954 {
955 e.printStackTrace();
956 }
957
958 turn_on_sat_status();
959
960 try
961 {
962 // try to download aGPS data!!
963 if (Navit.p.PREF_use_agps)
964 {
965 Navit.downloadGPSXtra(Navit.getBaseContext_);
966 }
967 }
968 catch (Exception e)
969 {
970 e.printStackTrace();
971 }
972
973 // if (Navit.METHOD_DEBUG) Navit.my_func_name(1);
974
975 }
976
977 public static void turn_off_precise_provider()
978 {
979 try
980 {
981 if (preciseProvider_s != null)
982 {
983 locationManager_s.removeUpdates(preciseLocationListener_s);
984 }
985 }
986 catch (Exception e)
987 {
988 e.printStackTrace();
989 }
990
991 turn_off_sat_status();
992 }
993
994 public static void turn_on_sat_status()
995 {
996 try
997 {
998 Navit.sats = 0;
999 Navit.satsInFix = 0;
1000 if (preciseProvider_s != null)
1001 {
1002 try
1003 {
1004 locationManager_s.removeGpsStatusListener(gps_status_listener_s);
1005 }
1006 catch (Exception e3)
1007 {
1008 e3.printStackTrace();
1009 }
1010 locationManager_s.addGpsStatusListener(gps_status_listener_s);
1011 sat_status_enabled = true;
1012 }
1013 }
1014 catch (Exception e)
1015 {
1016 e.printStackTrace();
1017 }
1018 //System.out.println("turn_ON_sat_status");
1019 }
1020
1021 public static void turn_off_sat_status()
1022 {
1023 try
1024 {
1025 Navit.sats = 0;
1026 Navit.satsInFix = 0;
1027 sat_status_enabled = true;
1028
1029 if (preciseProvider_s != null)
1030 {
1031 locationManager_s.removeGpsStatusListener(gps_status_listener_s);
1032 }
1033 }
1034 catch (Exception e)
1035 {
1036 e.printStackTrace();
1037 }
1038 //System.out.println("turn_off_sat_status");
1039 }
1040
1041 public static void turn_off_fast_provider()
1042 {
1043 try
1044 {
1045 fast_provider_status = 0;
1046 if (fastProvider_s != null)
1047 {
1048 locationManager_s.removeUpdates(fastLocationListener_s);
1049 }
1050 }
1051 catch (Exception e)
1052 {
1053 e.printStackTrace();
1054 }
1055 }
1056
1057 public static class TunnelExtrapolationThread extends Thread
1058 {
1059 private Boolean running;
1060 private static int interval_millis = 990;
1061
1062 TunnelExtrapolationThread()
1063 {
1064 this.running = true;
1065 }
1066
1067 public void run()
1068 {
1069 System.out.println("TunnelExtrapolationThread -- started --");
1070 while (this.running)
1071 {
1072 // request tunnel extrapolation from C code ------------------
1073 // request tunnel extrapolation from C code ------------------
1074
1075 String extrapolated_post_string = NavitGraphics.CallbackGeoCalc(12, 1, interval_millis);
1076
1077 if (extrapolated_post_string.equals("*ERROR*"))
1078 {
1079 System.out.println("extrapolated pos:*ERROR*");
1080 }
1081 else
1082 {
1083 try
1084 {
1085 // System.out.println("extrapolated pos:" + extrapolated_post_string);
1086 String tmp[] = extrapolated_post_string.split(":", 3);
1087 float lat = Float.parseFloat(tmp[0]);
1088 float lon = Float.parseFloat(tmp[1]);
1089 float dir = Float.parseFloat(tmp[2]);
1090 // System.out.println("extrapolated pos:" + lat + " " + lon + " " + dir);
1091
1092 Location l = new Location("ZANavi Tunnel Extrapolation");
1093 l.setLatitude(lat);
1094 l.setLongitude(lon);
1095 l.setBearing(dir);
1096 l.setSpeed(50.0f / 3.6f); // in m/s
1097 l.setAccuracy(4.0f); // accuracy 4 meters
1098 // NavitVehicle.update_compass_heading(dir);
1099 NavitVehicle.set_mock_location__fast(l);
1100 }
1101 catch (Exception e)
1102 {
1103 e.printStackTrace();
1104 }
1105 }
1106
1107 try
1108 {
1109 Thread.sleep(interval_millis);
1110 }
1111 catch (InterruptedException e)
1112 {
1113 }
1114 }
1115 }
1116
1117 public void stop_me()
1118 {
1119 this.running = false;
1120 this.interrupt();
1121 }
1122 }
1123
1124 static synchronized void turn_on_tunnel_extrapolation()
1125 {
1126 // if (Navit.METHOD_DEBUG) Navit.my_func_name(0);
1127
1128 if (!Navit.tunnel_extrapolation)
1129 {
1130 if (te_thread != null)
1131 {
1132 try
1133 {
1134 // try to clean up old thread
1135 te_thread.stop_me();
1136 te_thread = null;
1137 }
1138 catch (Exception e)
1139 {
1140 e.printStackTrace();
1141 }
1142 }
1143
1144 te_thread = new TunnelExtrapolationThread();
1145 te_thread.start();
1146 }
1147 Navit.tunnel_extrapolation = true;
1148
1149 // if (Navit.METHOD_DEBUG) Navit.my_func_name(1);
1150 }
1151
1152 static synchronized void turn_off_tunnel_extrapolation()
1153 {
1154 // if (Navit.METHOD_DEBUG) Navit.my_func_name(0);
1155
1156 if (Navit.tunnel_extrapolation)
1157 {
1158 if (te_thread != null)
1159 {
1160 try
1161 {
1162 // try to stop thread
1163 te_thread.stop_me();
1164 te_thread = null;
1165 }
1166 catch (Exception e)
1167 {
1168 e.printStackTrace();
1169 }
1170 }
1171 }
1172 Navit.tunnel_extrapolation = false;
1173
1174 // if (Navit.METHOD_DEBUG) Navit.my_func_name(1);
1175 }
1176
1177 public static void turn_off_all_providers()
1178 {
1179 turn_off_precise_provider();
1180 turn_off_fast_provider();
1181 }
1182
1183 public static void update_compass_heading(float heading)
1184 {
1185 compass_heading = heading;
1186 // use compass heading
1187 try
1188 {
1189 if (Navit.p.PREF_use_compass_heading_base)
1190 {
1191 if ((Navit.p.PREF_use_compass_heading_always) || (last_location.getSpeed() < GPS_SPEED_ABOVE_USE_FOR_HEADING))
1192 {
1193 if ((lastcompass_update_timestamp + 400) > System.currentTimeMillis())
1194 {
1195 //Log.e("NavitVehicle", "compass update to fast!");
1196 return;
1197 }
1198 lastcompass_update_timestamp = System.currentTimeMillis();
1199
1200 last_location.setBearing(compass_heading);
1201 // !! ugly hack to make map redraw !!
1202 // !! ugly hack to make map redraw !!
1203 // !! ugly hack to make map redraw !!
1204 if (last_location.getSpeed() == 0.0f)
1205 {
1206 float save_speed = last_location.getSpeed();
1207 last_location.setSpeed(0.2f);
1208 if (!Navit.DemoVehicle)
1209 {
1210 //Log.e("NavitVehicle", "call VehicleCallback 007:start");
1211 VehicleCallback2(last_location);
1212 /*
1213 * Message m2 = new Message();
1214 * m2.what = 2;
1215 * vehicle_handler_.handleMessage(m2);
1216 */
1217 //Log.e("NavitVehicle", "call VehicleCallback 007:end");
1218 }
1219 last_location.setSpeed(save_speed);
1220 }
1221 else
1222 {
1223 if (!Navit.DemoVehicle)
1224 {
1225 //Log.e("NavitVehicle", "call VehicleCallback 008");
1226 VehicleCallback2(last_location);
1227 }
1228 }
1229 // !! ugly hack to make map redraw !!
1230 // !! ugly hack to make map redraw !!
1231 // !! ugly hack to make map redraw !!
1232 }
1233 }
1234 }
1235 catch (Exception e)
1236 {
1237 //e.printStackTrace();
1238 }
1239 }
1240
1241 static void speech_recording_start()
1242 {
1243 speech_recording_started = true;
1244
1245 String pos_recording_filename_gpx_base = Navit.NAVIT_DATA_DEBUG_DIR + "zanavi_speech_recording";
1246 String pos_recording_filename_gpx = pos_recording_filename_gpx_base + ".gpx";
1247 String date = new SimpleDateFormat("yyyy-MM-dd_HHmmss", Locale.GERMAN).format(new Date());
1248 String pos_recording_filename_gpx_archive = pos_recording_filename_gpx_base + "_" + date + ".gpx";
1249
1250 String gpx_header_1 = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?>" + "<gpx version=\"1.1\" creator=\"ZANavi http://zanavi.cc\"\n" + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" + " xmlns=\"http://www.topografix.com/GPX/1/1\"\n" + " xsi:schemaLocation=\"http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd\">\n" + "<metadata>\n" + " <name>ZANavi Debug log</name>\n" + " <desc>ZANavi</desc>\n" + " <author>\n"
1251 + " <name>ZANavi</name>\n" + " </author>\n" + "</metadata>\n";
1252
1253 speech_recording_file_gpx = new File(pos_recording_filename_gpx);
1254
1255 try
1256 {
1257 if (speech_recording_file_gpx.exists())
1258 {
1259 // archive old GPX file
1260 speech_recording_file_gpx.renameTo(new File(pos_recording_filename_gpx_archive));
1261 }
1262 }
1263 catch (Exception e)
1264 {
1265 }
1266
1267 try
1268 {
1269 speech_recording_file_gpx = new File(pos_recording_filename_gpx);
1270 }
1271 catch (Exception e)
1272 {
1273 }
1274
1275 try
1276 {
1277 speech_recording_writer_gpx = new BufferedWriter(new FileWriter(speech_recording_file_gpx, true));
1278 speech_recording_writer_gpx.write(gpx_header_1);
1279 // speech_recording_writer_gpx.write("<rte>\n");
1280 }
1281 catch (Exception e)
1282 {
1283 }
1284 }
1285
1286 static void speech_recording_end()
1287 {
1288
1289 String gpx_trailer_1 = "</gpx>\n";
1290
1291 try
1292 {
1293 // speech_recording_writer_gpx.write("</rte>\n");
1294 speech_recording_writer_gpx.write(gpx_trailer_1);
1295 speech_recording_writer_gpx.flush();
1296 speech_recording_writer_gpx.close();
1297 }
1298 catch (Exception e)
1299 {
1300 }
1301 }
1302
1303 static void pos_recording_start()
1304 {
1305 is_pos_recording = true;
1306
1307 String pos_recording_filename_base = Navit.NAVIT_DATA_DEBUG_DIR + "zanavi_pos_recording";
1308 String pos_recording_filename = pos_recording_filename_base + ".txt";
1309 // String pos_recording_filename_gpx_base = Navit.NAVIT_DATA_DEBUG_DIR + "zanavi_pos_recording";
1310 //String pos_recording_filename_gpx = pos_recording_filename_gpx_base + ".gpx";
1311 // String date = new SimpleDateFormat("yyyy-MM-dd_HHmmss", Locale.GERMAN).format(new Date());
1312 //String pos_recording_filename_gpx_archive = pos_recording_filename_gpx_base + "_" + date + ".gpx";
1313 //String pos_recording_filename_archive = pos_recording_filename_base + "_" + date + ".txt";
1314
1315 // String gpx_header_1 = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?>" + "<gpx version=\"1.1\" creator=\"ZANavi http://zanavi.cc\"\n" + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" + " xmlns=\"http://www.topografix.com/GPX/1/1\"\n" + " xsi:schemaLocation=\"http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd\">\n" + "<metadata>\n" + " <name>ZANavi Debug log</name>\n" + " <desc>ZANavi</desc>\n" + " <author>\n"
1316 // + " <name>ZANavi</name>\n" + " </author>\n" + "</metadata>\n" + "<trk>\n" + "<trkseg>\n" + " <name>ACTIVE LOG</name>\n";
1317
1318 pos_recording_file = new File(pos_recording_filename);
1319 //pos_recording_file_gpx = new File(pos_recording_filename_gpx);
1320
1321 // try
1322 // {
1323 // if (pos_recording_file_gpx.exists())
1324 // {
1325 // // archive old GPX file
1326 // pos_recording_file_gpx.renameTo(new File(pos_recording_filename_gpx_archive));
1327 // }
1328 // }
1329 // catch (Exception e)
1330 // {
1331 // }
1332
1333 try
1334 {
1335 pos_recording_writer = new BufferedWriter(new FileWriter(pos_recording_file, true));
1336 // pos_recording_file_gpx = new File(pos_recording_filename_gpx);
1337 }
1338 catch (Exception e)
1339 {
1340 }
1341 }
1342
1343 static void pos_recording_end()
1344 {
1345 is_pos_recording = false;
1346
1347 // String gpx_trailer_1 = "</trkseg>\n" + "</trk>\n" + "</gpx>\n";
1348
1349 try
1350 {
1351 //pos_recording_writer_gpx.write(gpx_trailer_1);
1352
1353 pos_recording_writer.close();
1354 // pos_recording_writer_gpx.close();
1355 }
1356 catch (Exception e)
1357 {
1358 }
1359 }
1360
1361 static public String customNumberFormat_(String pattern, double value)
1362 {
1363 // NumberFormat myFormatter = DecimalFormat.getInstance(Locale.US);
1364
1365 DecimalFormatSymbols otherSymbols = new DecimalFormatSymbols(Locale.US);
1366 otherSymbols.setDecimalSeparator('.');
1367 DecimalFormat df = new DecimalFormat(pattern, otherSymbols);
1368
1369 String output = df.format(value);
1370 return (output);
1371 }
1372
1373 static void speech_recording_add(double lat, double lon, String text, long time)
1374 {
1375 try
1376 {
1377 String date_time_gpx = (String) DateFormat.format("yyyy-MM-dd'T'HH:mm:ss'Z'", time);
1378 // System.out.println("33XX"+date_time_gpx+"YY");
1379
1380 // speech_recording_writer_gpx.write(" <trkpt lat=\"" + customNumberFormat_("####.######", lat) + "\" lon=\"" + customNumberFormat_("####.######", lon) + "\"><time>2014-10-02T09:30:10Z</time><speed>" + customNumberFormat_("####.##", speed) + "</speed><course>" + customNumberFormat_("####.#", bearing) + "</course></trkpt>\n");
1381 // speech_recording_writer_gpx.write(" <rtept lat=\"" + customNumberFormat_("####.######", lat) + "\" lon=\"" + customNumberFormat_("####.######", lon) + "\"><name>" + text + "</name></rtept>" + "\n");
1382 speech_recording_writer_gpx.write(" <wpt lat=\"" + customNumberFormat_("####.######", lat) + "\" lon=\"" + customNumberFormat_("####.######", lon) + "\"><time>" + date_time_gpx + "</time>" + "<name>" + text + "</name><sym>Dot</sym><type>Dot</type></wpt>" + "\n");
1383 }
1384 catch (Exception e)
1385 {
1386 }
1387 }
1388
1389 static void pos_recording_add(int cmd, double lat, double lon, double speed, double bearing, long time)
1390 {
1391 if (ZANaviDebugReceiver.dont_save_loc == true)
1392 {
1393 // dont save (already saved) log
1394 return;
1395 }
1396
1397 if (cmd == 0) // empty lines
1398 {
1399 try
1400 {
1401 pos_recording_writer.write("\n");
1402 pos_recording_writer.write("\n");
1403 pos_recording_writer.write("\n");
1404 pos_recording_writer.write("\n");
1405 }
1406 catch (Exception e)
1407 {
1408 }
1409 }
1410 else if (cmd == 1) // POS
1411 {
1412
1413 // try
1414 // {
1415 // pos_recording_writer_gpx.write(" <trkpt lat=\"" + customNumberFormat_("####.######", lat) + "\" lon=\"" + customNumberFormat_("####.######", lon) + "\"><time>2014-10-02T09:30:10Z</time><speed>" + customNumberFormat_("####.##", speed) + "</speed><course>" + customNumberFormat_("####.#", bearing) + "</course></trkpt>\n");
1416 // }
1417 // catch (Exception e)
1418 // {
1419 // }
1420
1421 try
1422 {
1423 pos_recording_writer.write("POS:" + "\"" + customNumberFormat_("####.######", lat) + "," + customNumberFormat_("####.######", lon) + "," + customNumberFormat_("####.##", speed) + "," + customNumberFormat_("####.##", bearing) + "\"" + "\n");
1424 if (Navit.OSD_route_001.arriving_time_valid)
1425 {
1426 pos_recording_writer.write("REM:" + "\"ETA:" + Navit.OSD_route_001.arriving_time + "\"" + "\n");
1427 }
1428 }
1429 catch (Exception e)
1430 {
1431 }
1432 }
1433 else if (cmd == 2) // CLR
1434 {
1435 try
1436 {
1437
1438 // before "CLR" rotate recording file --------------------------
1439 // before "CLR" rotate recording file --------------------------
1440 String pos_recording_filename_base = Navit.NAVIT_DATA_DEBUG_DIR + "zanavi_pos_recording";
1441 String pos_recording_filename = pos_recording_filename_base + ".txt";
1442 String date = new SimpleDateFormat("yyyy-MM-dd_HHmmss", Locale.GERMAN).format(new Date());
1443 String pos_recording_filename_archive = pos_recording_filename_base + "_" + date + ".txt";
1444
1445 try
1446 {
1447 if (pos_recording_file.exists())
1448 {
1449 pos_recording_writer.close();
1450
1451 // archive old GPX file
1452 pos_recording_file.renameTo(new File(pos_recording_filename_archive));
1453 pos_recording_file = new File(pos_recording_filename);
1454 pos_recording_writer = new BufferedWriter(new FileWriter(pos_recording_file, true));
1455 }
1456 }
1457 catch (Exception e)
1458 {
1459 }
1460 // before "CLR" rotate recording file --------------------------
1461 // before "CLR" rotate recording file --------------------------
1462
1463 pos_recording_writer.write("CLR:" + "\"\"" + "\n");
1464 }
1465 catch (Exception e)
1466 {
1467 }
1468 }
1469 else if (cmd == 3) // DST
1470 {
1471 try
1472 {
1473 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.GERMAN);
1474 String currentDateandTime = sdf.format(new Date());
1475 pos_recording_writer.write("REM:" + "\"Date:" + currentDateandTime + "\"" + "\n");
1476 pos_recording_writer.write("DST:" + "\"" + customNumberFormat_("####.######", lat) + "," + customNumberFormat_("####.######", lon) + "\"" + "\n");
1477 }
1478 catch (Exception e)
1479 {
1480 }
1481 }
1482 }
1483
1484 static int distanceBetween(float lat1, float lon1, float lat2, float lon2)
1485 {
1486 int ret = -1;
1487
1488 float[] res = new float[3];
1489
1490 try
1491 {
1492 android.location.Location.distanceBetween(lat1, lon1, lat2, lon2, res);
1493 ret = (int) (res[0]);
1494 }
1495 catch (Exception e)
1496 {
1497 }
1498
1499 return ret;
1500 }
1501
1502 static int distanceBetween(double lat1, double lon1, double lat2, double lon2)
1503 {
1504 int ret = -1;
1505
1506 float[] res = new float[3];
1507
1508 try
1509 {
1510 android.location.Location.distanceBetween(lat1, lon1, lat2, lon2, res);
1511 ret = (int) (res[0]);
1512 }
1513 catch (Exception e)
1514 {
1515 }
1516
1517 return ret;
1518 }
1519
1520 }

   
Visit the ZANavi Wiki