Geolocation may be used in weather apps to access the user's location and show the weather of the place where the user lives.
The Code to do this is below
Code :
if(navigator.geolocation){
navigator.geolocation.getCurrentPosition(function (position){
const pos = {
lat: position.coords.latitude,
lng: position.coords.longitude
};
const map = new google.maps.Map(document.getElementById('map'), {
zoom: 8,
center: pos
});
const marker = new google.maps.Marker({
position: pos,
map: map
});
});
} else{
console.log("Geolocation not supported");
}
0 Comments
Ask Your Queries in the comments