Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to develop electronic compass with HTML5

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

Today, I would like to share with you the relevant knowledge about how to develop the electronic compass with HTML5. The content is detailed and the logic is clear. I believe most people still know too much about this, so share this article for your reference. I hope you can get something after reading this article. Let's take a look at it.

When explaining the electronic compass, we need to understand two concepts: one is the geographical North Pole, the other is the geomagnetic North Pole.

1. Understand the geographical north pole and geomagnetic north pole

The geographical North Pole is the concept on our traditional paper map, that is, north to south, left, west, right, east. If we connect the north and south poles on the map into a line, it is the axis of the earth's rotation.

The north and south poles of geomagnetism are the two strongest places of the earth's magnetic field, while the South Pole of geomagnetism is near the geographical North Pole, and the geomagnetic North Pole is near the Geographic South Pole. The angle between the north and south poles of geography and the north and south poles of geomagnetism is called magnetic declination.

Please note that the geomagnetic north and south poles change, so every time, or every change of city, you need to use correction software (or interface) to correct the electronic compass to match the geomagnetism to prevent inaccurate pointing.

If you have used the compass on your smartphone before, then we all know that there is a correction process, and the HTML5 standard also provides us with an interface for Web correction, as follows:

Window.addEventListener ("compassneedscalibration", function (event) {

Alert your compass needs to be corrected! Hold your equipment and draw a figure 8 facing the sky. Three pros and cons.')

Event.preventDefault ()

}, true)

2. HTML5 electronic compass development example

In this example, we are still developing through events related to DeviceOrientation, as shown in the code listing:

Compass

Body {background-color:#404041;}

Compass

The direction sensor is called up through the Device API,HTML5 application in the HTML5 experience version of the Openg browser. Sensor-based data

It can help you determine your direction. This demo uses this function to make a web compass.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report