官术网_书友最值得收藏!

Plotting the user's location

Most mobile devices are fitted with a geolocation device, or the location can be determined using secondary information such as IP or even falling back to user input. This is exposed for the modern web developer to use in applications via the HTML5 geolocation API at http://www.w3.org/TR/geolocation-API/.

As with the desktop notifications, the user must give permission for the page to use their location. A further little hurdle is that location features do not work on Dartium. To try out this feature of the application, use pub build to create the JavaScript version and use another browser:

Plotting the user's location

The Locate button on the page will attempt to obtain the user's position and draw it on the page by adding it to the featurePlotter class instance:

locateUser(Event evt) async {
  Geoposition geoPos = await window.navigator.geolocation.getCurrentPosition();
  MapIndicator mapIndicator;
  var pos =
      featPlotter.toPoint(geoPos.coords.longitude, geoPos.coords.latitude);
  mapIndicator = new MapIndicator(pos.x, pos.y, quakeMap.mapCtx, 4);
  mapIndicator.colorPrimary = "#0000ff";
  mapIndicator.colorSecondary = "#00ffff";
  featPlotter.userLocation.add(mapIndicator);
}

The coordinates are converted in the same manner as the quakes, and the indicator is changed to a blue color so that it will stand out on the map, as shown in the following screenshot:

Plotting the user's location

Once the application is compiled to JavaScript, the geolocation data is made available with user permission and the blue dot indicates the user's location, which in this instance is the relatively earthquake-free United Kingdom.

Note

The Dart VM that runs in the command line and Dartium is not the only manifestation. The Dart team is working on two experimental versions of Dart in other contexts that vary significantly from the main Dart VM. Currently, both operate in a mobile context and focus on concurrency and high performance.

Fletch runs on desktop OSs, but is intended for Android and iOS execution with no JIT. Fletch takes a somewhat opposite approach to the highly asynchronous Dart, favoring user-level threads that are blocked but holding onto just a few resources. Fletch offers an interesting prospect for sharing the same code on different platforms; this would be a major productivity boost for mobile developers.

https://github.com/dart-lang/fletch

Sky is Android, only at the time of writing, and ambitiously aims to have highly responsive applications running at 120FPS. To achieve this, it prioritizes the user interface so that it can keep an 8ms response even when other processing is taking place. Currently, it can potentially run wherever the Dart VM can.

https://github.com/domokit/sky_engine/tree/master/sky/packages/sky

The Fletch and Sky prototypes, if successful, are likely to be mobile or server virtual machines and not embedded in a web server.

主站蜘蛛池模板: 额尔古纳市| 梁山县| 张掖市| 宜丰县| 古田县| 哈巴河县| 炉霍县| 额尔古纳市| 阿克| 崇义县| 镇远县| 晴隆县| 石屏县| 广汉市| 稻城县| 吴忠市| 林西县| 时尚| 昭通市| 上犹县| 禹州市| 扶沟县| 古丈县| 龙江县| 故城县| 武清区| 桂阳县| 龙游县| 黄冈市| 临漳县| 柳州市| 吐鲁番市| 平山县| 于田县| 大同县| 乌拉特中旗| 漠河县| 靖江市| 同心县| 平江县| 遂昌县|