HTML5 GeoLocation Example

Developer
Size
3,685 Kb
Views
24,288

How do I make an html5 geolocation example?

Light weight geo location example that returns the users address, city, etc.... What is a html5 geolocation example? How do you make a html5 geolocation example? This script and codes were developed by Adam Grayson on 10 November 2022, Thursday.

HTML5 GeoLocation Example Previews

HTML5 GeoLocation Example - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>HTML5 GeoLocation Example</title> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/meyer-reset/2.0/reset.min.css"> <link rel="stylesheet" href="css/style.css">
</head>
<body> // Be sure to enable-allow your browsers geoLocation features for this page
// Address wont be 100 percent accurate- but has increased performance on devices with GPS features such as phones and tablets
//Inspired by 'http://petarstrinic.com/visitors-zip-code-using-html5-geolocation-google-maps-api/'
.geoLocation .address p searching... .city p searching... .state p searching... .zip p searching... .country p searching... <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
<script src='https://maps.googleapis.com/maps/api/js?sensor=false'></script> <script src="js/index.js"></script>
</body>
</html>

HTML5 GeoLocation Example - Script Codes CSS Codes

html, body { width: 100%; height: 100%; background: #12aeef; font: 25px/35px "TrebuchetMS", trebuchet, sans-serif; color: #ffffff; text-align: center; position: relative; display: table;
}
html .geoLocation, body .geoLocation { display: table-cell; vertical-align: middle;
}

HTML5 GeoLocation Example - Script Codes JS Codes

(function() { var getLocation, setAddressText, showPosition; getLocation = function() { if (navigator.geolocation) { return navigator.geolocation.getCurrentPosition(showPosition); } else { return alert("Geolocation is not supported by this browser."); } }; showPosition = function(position) { var lat, long, point; lat = position.coords.latitude; long = position.coords.longitude; point = new google.maps.LatLng(lat, long); new google.maps.Geocoder().geocode({ latLng: point }, function(res, status) { var address, city, country, state, zip; address = res[0].formatted_address.match(/[^,]+/); zip = res[0].formatted_address.match(/,\s\w{2}\s(\d{5})/); city = res[0].formatted_address.match(/,\s(\w+),\s\w{2}/); state = res[0].formatted_address.match(/,\s\w+,\s(\w{2})/); country = res[0].formatted_address.match(/\d,\s(.+)$/); setAddressText(address[0], city[1], state[1], zip[1], country[1]); }); }; setAddressText = function(address, city, state, zip, country) { $('.address p').text(address); $('.city p').text(city); $('.state p').text(state); $('.zip p').text(zip); return $('.country p').text(country); }; getLocation();
}).call(this);
HTML5 GeoLocation Example - Script Codes
HTML5 GeoLocation Example - Script Codes
Home Page Home
Developer Adam Grayson
Username agrayson
Uploaded November 10, 2022
Rating 3
Size 3,685 Kb
Views 24,288
Do you need developer help for HTML5 GeoLocation Example?

Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!

Adam Grayson (agrayson) Script Codes
Create amazing art & images with AI!

Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!