Google Maps - Reverse Geolocation

Size
2,639 Kb
Views
6,072

How do I make an google maps - reverse geolocation?

Example of reverse geolocation with Google Maps API.. What is a google maps - reverse geolocation? How do you make a google maps - reverse geolocation? This script and codes were developed by Thulio Philipe on 09 January 2023, Monday.

Google Maps - Reverse Geolocation Previews

Google Maps - Reverse Geolocation - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Google Maps - Reverse Geolocation</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> <div id="map-canvas"></div> <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?signed_in=true'></script> <script src="js/index.js"></script>
</body>
</html>

Google Maps - Reverse Geolocation - Script Codes CSS Codes

#map-canvas { width: 100%; height: 500px; border: 1px solid black; display: inline-block;
}

Google Maps - Reverse Geolocation - Script Codes JS Codes

$(document).on('ready', function() {	getLocation();
});
// pegando a localização do usuário
function getLocation() {	// solicitando a geolocalização do usuário	if (navigator.geolocation) {	navigator.geolocation.getCurrentPosition(success, error);	} else {	error('Não suportado!');	}	// Função de sucesso para a geolocalização.	function success(position) {	console.log("A latitude é: " + position.coords.latitude);	console.log("A longitude é: " + position.coords.longitude);	// criando geocoder	geocoder = new google.maps.Geocoder();	// mostrando o mapa na tela	var latlng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);	var mapOptions = {	zoom: 10,	center: latlng,	mapTypeId: 'roadmap'	}	map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);	// criando infowindow	var infowindow = new google.maps.InfoWindow;	// efetuando o geocode a partir da localização do usuário	geocoder.geocode({'latLng': latlng}, function(results, status) {	if (status == google.maps.GeocoderStatus.OK) {	if (results[1]) {	map.setZoom(11);	marker = new google.maps.Marker({	position: latlng,	map: map	});	infowindow.setContent(results[1].formatted_address);	infowindow.open(map, marker);	} else {	alert('Sem resultados..');	}	} else {	alert('Geocoder falhou por conta de: ' + status);	}	});	// executa o mapa passando a função success quando o dom fizer o load	google.maps.event.addDomListener(window, 'load', success);	}	// Função de error caso o navegador não suporte a geolocalização	function error(msg) {	console.log('error');	}
}
Google Maps - Reverse Geolocation - Script Codes
Google Maps - Reverse Geolocation - Script Codes
Home Page Home
Developer Thulio Philipe
Username thulioph
Uploaded January 09, 2023
Rating 3
Size 2,639 Kb
Views 6,072
Do you need developer help for Google Maps - Reverse Geolocation?

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!

Thulio Philipe (thulioph) Script Codes
Create amazing sales emails 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!