Position and distance tracker with the GeoLocation API and Google Maps API
In Chapter 2, Practical Dart, we learned about the dart:js
library. We saw that we can proxy JavaScript objects using the JsObject
class in Dart. We're going to use the JsObject
class a lot right now because this app will use the Google Maps API, which is a JavaScript API that we'll control from Dart.
Note
There's a Dart wrapper (https://pub.dartlang.org/packages/google_maps) for the Google Maps API, which you would probably prefer in a real-world app, but for demonstration purposes, we'll write everything by ourselves.
First, include the Google Maps API before including any Dart script:
<script src="http://maps.../api/js?libraries=geometry"></script> <script type="application/dart" src="main.dart"></script>
Note the ?libraries=geometry
parameter in the URL. This tells Google to include an additional library in the API, which we need in order to calculate the distance between two GPS locations.
We...