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

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.

主站蜘蛛池模板: 偏关县| 辽中县| 宽城| 弥渡县| 墨竹工卡县| 江陵县| 日土县| 隆林| 蓬溪县| 区。| 札达县| 信阳市| 中江县| 九龙坡区| 金秀| 齐齐哈尔市| 穆棱市| 乌兰县| 乐陵市| 尼木县| 霍州市| 太仓市| 盐津县| 棋牌| 宝清县| 阜宁县| 南召县| 长岛县| 亳州市| 马关县| 德江县| 兴义市| 石狮市| 湖州市| 芮城县| 大连市| 尼木县| 上思县| 玉山县| 滨海县| 改则县|