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

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.

主站蜘蛛池模板: 永定县| 灵寿县| 陕西省| 自治县| 伊金霍洛旗| 大荔县| 沙湾县| 安平县| 静安区| 普宁市| 若尔盖县| 华池县| 玉树县| 和田县| 施甸县| 临湘市| 惠来县| 莲花县| 绍兴县| 兰西县| 崇明县| 西乌| 开阳县| 福州市| 藁城市| 高唐县| 娄烦县| 剑阁县| 鹰潭市| 图们市| 凌源市| 元谋县| 平湖市| 札达县| 扬中市| 澄江县| 桓台县| 嘉黎县| 泾川县| 湾仔区| 镇江市|