Inhaltsverzeichnis
Syntax
Methods of geolocation+63
Example of HTML Geolocation
Example #3
結論
Heim Web-Frontend HTML-Tutorial HTML-Geolokalisierung

HTML-Geolokalisierung

Sep 04, 2024 pm 04:51 PM
html html5 HTML Tutorial HTML Properties HTML tags

Up till now, we had seen many features getting designed using HTML. One of the latest and advanced features included in HTML is geolocation. HTML geolocation is most useful for detecting user location on a map. So this feature gets designed in HTML to identify the exact position of the user on the map. This position of the user can be identified by using attributes called latitude and longitude of specific user position. This can retrieve information only when the user allows it to access the location. This HTML feature mostly used for local business purpose, for finding restaurants, or choosing the location on the map.

Syntax

Here is the syntax for HTML geolocation is as follows: One can use location API, which will use global navigator object, which is as shown below:

var locat = navigator.geolocation;

Into the above syntax navigator. Geolocation responsible for the user browser to get access to their location information; one access is defined. The browser can provide the best functionality that is present over there on the device, so one can easily access this data.

This data can be accessed efficiently by using different ways like getCurrentPosition to know the current position of user or device, watchPosition, which is helpful whenever the position of the device is getting changed and one more way like clearWatch, which helps to clear all calls in geolocation functionality.

This functionality works on some interfaces those are as follows:

  1. Geolocation: It’s of one the most important API of the main class, which includes some methods that help to obtain user’s current location, watch for changes in their position, etc.
  2. GeolocationPosition: This is used to define the position of the user. Whenever a success call gets identified in one of the geolocation, then it will coordinate with its object instance.
  3. Geolocation coordinates: This helps to identify coordinates for the user position.
  4. GeolocationPositionErrror: This interface is called for the unsuccessful call is return into the methods which are included in the geolocation.
  5. Geolocation: This is useful when a geolocation object instance is called in geolocation. So it’s possible to access all other functionality from here.

Methods of geolocation+63

There are total 3 methods used in HTML geolocation for defining position with geolocation interface; those are as follows:

  1. getCurrentPosition(): This basic method in HTML geolocation helps to detect the current geographic location of either device or the user and its return data on the map. This method works on different parameters like success, error, options.
  2. watchPosition(): Whenever the user wants to check position after device location changed, this is called within coding to check changed device position. This method invokes error call back functions like Unknown random errors. Users are not allowing to share location if given location information is not available and the given requested location is timed out.
  3. clearWatch(): one may be able to cancel previous watchPosition() call as well as it will cancel ongoing watchPosition call by using this method of HTML geolocation

Example of HTML Geolocation

Here are the Examples of HTML Geolocation

Example #1

In the first example, we are going to see whether our browser will support or not for this geolocation feature; here is the code for it as mentioned below:

HTML code:

<!DOCTYPE html>
<html>
<head>
<title>HTML Geolocation</title>
</head>
<body>
<h4>HTML Geolocation</h4>
<button onclick="getlocation()">Click Here</button>
<br>
<br>
<br>
<p>As we all know, geolocation is the feature used for positioning the exact location of the user or device. But the first step we have to check whether our browser is going to support this geolocation feature or not. </p>
<h4> This Example illustrates whether our browser is going to support for geolocation or not.</h4>
<div id="geolocation1"></div>
<script>
var x= document.getElementById("geolocation1");
function getlocation() {
if(navigator.geolocation){
alert("My browser is going to support Geolocation feature")
}
else
{
alert("Oops! My browser is not going to support Geolocation feature")
}
}
</script>
</body>
</html>

Output:

HTML-Geolokalisierung

HTML-Geolokalisierung

Example #2

In this example, we are going to show the exact location with the HTML geolocation feature, so it will show the exact position on the map with attribute value for latitude and longitude is as follows:

HTML code:

<!DOCTYPE html>
<html>
<body>
<h4>HTML Geolocation Latitude and Longitude Value</h4>
<p>Example showing Geolocation , It will give values for the latitude and longitude after clicking below button</p>
<button onclick="getLocation()">Click Here</button>
<p id="geolocation"></p>
<script>
var x = document.getElementById("geolocation");
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showgeolocPosition);
} else {
x.innerHTML = "This code is not supported in geolocation for your browser";
}
}
function showgeolocPosition(position) {
x.innerHTML = "Latitude Attribute Value: "     + position.coords.latitude +
"<br>Longitude Attribute Value: "  + position.coords.longitude;
}
</script>
</body>
</html>

Output:

HTML-Geolokalisierung

After clicking on the button, the output will be as shown below

HTML-Geolokalisierung

Example #3

In this example, we are going to show the exact location with the HTML geolocation feature, so it will show the exact position on the map with attribute value for latitude and longitude is as follows:

HTML code:

<!DOCTYPE html>
<html>
<head>
<title>Geolocation</title>
</head>
<style>
#mapdemo{
width: 500px;
height: 500px;
margin-left: 200px;
}
</style>
<body>
<h2>Find Your Location on Google Map</h2>
<p>In this Example we are going to see exact location on Google map, where actually we are.</p>
<button onclick="getlocation();"> Show my position on Map </button>
<div id="mapdemo">
</div>
<script src="https://maps.google.com/maps/api/js?sensor=false">
</script>
<script type="text/javascript">
function getlocation(){
if(navigator.geolocation){
navigator.geolocation.getCurrentPosition(showPos, showErr);
}
else{
alert("Sorry! your Browser does not support Geolocation API")
}
}
// Current Poistion on Google Map
function showPos(position){
latt = position.coords.latitude;
long = position.coords.longitude;
var lattlong = new google.maps.LatLng(latt, long);
var myOptions = {
center: lattlong,
zoom: 15,
mapTypeControl: true,
navigationControlOptions: {style:google.maps.NavigationControlStyle.SMALL}
}
var maps = new google.maps.Map(document.getElementById("mapdemo"), myOptions);
var markers =
new google.maps.Marker({position:lattlong, map:maps, title:"Your position on map!"});
}
function showErr(error) {
switch(error.code){
case error.PERMISSION_DENIED:
alert("User or Device not allow to accept your request for Geolocation.");
break;
case error.POSITION_UNAVAILABLE:
alert("USer or Device exact location information is currently unavailable.");
break;
case error.TIMEOUT:
alert("Requested request is getting time out .");
break;
case error.UNKNOWN_ERROR:
alert("Something unknown error is accrued.");
break;
}
}        </script>
</body>
</html>

Output:

HTML-Geolokalisierung

結論

從以上所有資訊中,我們了解到 HTML 地理定位是一種用於在地圖上識別裝置或使用者位置的功能。

它使用緯度和經度屬性來識別使用者的確切位置。

此功能適用於不同的方法,例如 getCurrentPosition、watchPosition 和clearWatch。

Das obige ist der detaillierte Inhalt vonHTML-Geolokalisierung. Für weitere Informationen folgen Sie bitte anderen verwandten Artikeln auf der PHP chinesischen Website!

Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn

Heiße KI -Werkzeuge

Undress AI Tool

Undress AI Tool

Ausziehbilder kostenlos

Undresser.AI Undress

Undresser.AI Undress

KI-gestützte App zum Erstellen realistischer Aktfotos

AI Clothes Remover

AI Clothes Remover

Online-KI-Tool zum Entfernen von Kleidung aus Fotos.

Stock Market GPT

Stock Market GPT

KI-gestützte Anlageforschung für intelligentere Entscheidungen

Heiße Werkzeuge

Notepad++7.3.1

Notepad++7.3.1

Einfach zu bedienender und kostenloser Code-Editor

SublimeText3 chinesische Version

SublimeText3 chinesische Version

Chinesische Version, sehr einfach zu bedienen

Senden Sie Studio 13.0.1

Senden Sie Studio 13.0.1

Leistungsstarke integrierte PHP-Entwicklungsumgebung

Dreamweaver CS6

Dreamweaver CS6

Visuelle Webentwicklungstools

SublimeText3 Mac-Version

SublimeText3 Mac-Version

Codebearbeitungssoftware auf Gottesniveau (SublimeText3)

Wie man ein Video in HTML automatisch spielt Wie man ein Video in HTML automatisch spielt Sep 25, 2025 am 05:04 AM

Um eine automatische Video -Wiedergabe zu erreichen, muss das Video gedämpft werden. Verwenden Sie das Autoplay- und gedämpfte Eigenschaften, um sicherzustellen, dass HTML -Videos in modernen Browsern automatisch abgespielt werden. Wenn Sie Loops abspielen möchten, können Sie Schleifenattribute hinzufügen. Wenn Sie Steuerelemente entfernen, wird die Steuerleiste nicht angezeigt.

Was ist der Unterschied zwischen Q- und Blockquote -Tags in HTML? Was ist der Unterschied zwischen Q- und Blockquote -Tags in HTML? Sep 25, 2025 am 06:14 AM

Das Q -Tag wird für kurze Inline -Zitate verwendet, die für kurze Zitate in Sätzen geeignet sind, und Browser fügen normalerweise automatisch Zitate hinzu. 2. Das Blockquote -Tag wird für unabhängige Zitate mit langen Absätzen verwendet, häufig mit Einrückung zur visuellen Unterscheidung und unterstützt die Quelle, die durch Zitattribute gekennzeichnet ist. 3. Die Wahl von Q oder Blockquote sollte auf der Länge und dem Kontext des Zitats basieren, die beide die Semantik und Zugänglichkeit des Inhalts verbessern.

So importieren Sie Lesezeichen aus anderen Browsern mit Chrome Browser_Crome Lesezeichen Datenverbindungshandbuch importieren So importieren Sie Lesezeichen aus anderen Browsern mit Chrome Browser_Crome Lesezeichen Datenverbindungshandbuch importieren Sep 25, 2025 am 10:18 AM

Zunächst können Sie andere Browserdaten direkt über die integrierte Funktion "Lesezeichen und Einstellungen" von Chrome migrieren. Zweitens können Sie sie über den Lesezeichen -Manager importieren, wenn Sie bereits eine HTML -Format -Lesezeichendatei haben. Schließlich können Sie die ursprüngliche Browser -Lesezeichendatei manuell kopieren und in HTML konvertieren und dann importieren.

Wie erstelle ich eine einfache Akkordeonkomponente in HTML5? Wie erstelle ich eine einfache Akkordeonkomponente in HTML5? Sep 25, 2025 am 04:20 AM

Verwenden Sie HTML5-Details und zusammenfassende Elemente, um einfache, barrierfreie Faltplatten zu erstellen, Stile über CSS zu verschönern und JavaScript zu verwenden, um interaktive Auswirkungen der Erweiterung von nur einem Panel zu erzielen, wodurch grundlegende und vollständige Akkordeionskomponenten ohne eine Drittanbieterbibliothek ermöglicht werden.

So stellen Sie den Chrombrowser ein, um die Header und die Fußzeile zu entfernen, wenn Sie drucken So stellen Sie den Chrombrowser ein, um die Header und die Fußzeile zu entfernen, wenn Sie drucken Sep 25, 2025 am 09:54 AM

1. Öffnen Sie die Webseiten -Druckschnittstelle, klicken Sie auf "Weitere Einstellungen" und deaktivieren Sie "Header und Fußzeile", um automatisch URLs, Daten und andere Informationen hinzugefügt. 2. Durch Hinzufügen des CSS -Stils von @mediaprint {@page {margin: 0}} dem Webseitencode können die Standardmargen, Header und Fußzeile gelöscht werden. 3. Installieren Sie Druckerweiterungen von Drittanbietern wie Printedit, mit denen Druckinhalte flexibler bearbeiten und die Standard-Header und die Fußzeile deaktivieren können.

So leiten Sie einen Benutzer mit einem Meta -Tag in HTML auf eine andere Seite um So leiten Sie einen Benutzer mit einem Meta -Tag in HTML auf eine andere Seite um Sep 25, 2025 am 04:56 AM

Verwenden Sie Tags, um die HTML -Seitenumleitung zu realisieren, das Tag in einen Teil zu setzen und Content = "0; url = Ziel -URL" zu setzen, um einen sofortigen Sprung zu erreichen. 2. Sie können den Verzögerungssprung festlegen, indem Sie die Anzahl der Sekunden im Inhalt (z. B. 5) erhöhen, um die Benutzererfahrung zu verbessern. 3.. Es wird empfohlen, mit der Anzeige von Eingabeaufforderungsinformationen und alternativen Links zusammenzuarbeiten, um die Zugänglichkeit und Kompatibilität zu gewährleisten. Die serverseitige 301/302 Umleitung sollte jedoch Priorität haben, um eine bessere SEO und Zuverlässigkeit zu erhalten. Die endgültige vollständige Implementierungsmethode enthält Eingabeaufforderung und manuelle Sprungverbindungen und endet mit einem vollständigen Satz.

Was ist der DocType in HTML Was ist der DocType in HTML Sep 26, 2025 am 05:43 AM

Die Antwort lautet, HTML5 -Dokumenttypen zu deklarieren und sicherzustellen, dass der Browser die Seite im Standardmodus rendert. Es verhindert, dass der Browser den Mackenmodus eingeht und die Konsistenz der Kreuzbrowser gewährleistet. Der DocType von HTML5 ist prägnant und unempfindlich und für alle modernen Webentwicklung geeignet. Die alte Version von docType ist veraltet und wird nur bei der Wartung alter Websites verwendet. Neue Projekte sollten immer verwendet werden.

So exportieren Sie Lesezeichen nach QQ -Browser QQ -Browser -Lesezeichen als HTML -Dateien Betriebstutorial So exportieren Sie Lesezeichen nach QQ -Browser QQ -Browser -Lesezeichen als HTML -Dateien Betriebstutorial Sep 25, 2025 am 10:27 AM

Wenn Sie Lesezeichen im QQ-Browser als HTML-Dateien für die Verwendung in anderen Browsern oder zur Sicherung speichern möchten, können Sie den Exportbetrieb über die integrierte Lesezeichenverwaltungsfunktion abschließen. Im Folgenden sind die spezifischen Betriebsschritte: Die Betriebsumgebung dieses Artikels: Xiaomi 14, Android 14 1. Exportieren Sie die Seite "Lesezeichenverwaltung" über die Seite "Lesezeichen". Der QQ -Browser bietet eine Lesezeichenverwaltungsschnittstelle. In dieser Schnittstelle können Benutzer alle Lesezeichen direkt in Standard-HTML-Formatdateien exportieren, die die plattformübergreifende Migration erleichtern. 1. Öffnen Sie den QQ -Browser und klicken Sie auf das Lesezeichen -Symbol in der Menüleiste unten. 2. Nach dem Eingeben der Lesezeichenseite klicken Sie in der oberen rechten Ecke auf das Menü Drei-Punkte-Menü (weitere Optionen). 3. Wählen Sie Lesezeichenverwaltung im Popup-Menü. 4. Klicken Sie auf der Seite des Lesezeichenmanagements oben importieren/exportieren

See all articles