-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmaps.js
131 lines (96 loc) · 3.07 KB
/
maps.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
var loc = [{ lat: 17, lng: 81 }, { lat: 15, lng: 79 }]
// Check if geolocation is supported by the browser
if ("geolocation" in navigator) {
// Prompt user for permission to access their location
navigator.geolocation.getCurrentPosition(
// Success callback function
(position) => {
// Get the user's latitude and longitude coordinates
const lat = position.coords.latitude;
const lng = position.coords.longitude;
// var lat1 = parseFloat(lat);
// var lng1 = parseFloat(lng);
initMap(lat, lng);
// Do something with the location data, e.g. display on a map
console.log(`Latitude: ${lat}, longitude: ${lng}`);
},
// Error callback function
(error) => {
// Handle errors, e.g. user denied location sharing permissions
console.error("Error getting user location:", error);
}
);
} else {
// Geolocation is not supported by the browser
console.error("Geolocation is not supported by this browser.");
}
let map;
async function initMap(lat1, lng1) {
const { Map } = await google.maps.importLibrary("maps");
map = new Map(document.getElementById("map"),{
center: { lat: +lat1, lng: +lng1 },
zoom: 19,
mapTypeId: "satellite"
});
// const pinBackground = new PinElement({
// background: "#FBBC04",
// });
new google.maps.Marker({
position: { lat: lat1, lng: lng1 },
map: map,
icon: 'https://maps.google.com/mapfiles/ms/icons/blue-dot.png'
});
// for(var i = 0; i < loc.length; i++){
// new google.maps.Marker({
// position: loc[i],
// map: map,
// });
// }
for (var i = 1; i < 40; i++)
loc.push({ lat: lat1 + (0.0001 * i), lng: lng1 + (0.0001 * i) });
loc.forEach(element => {
if ((lat1 - 0.001 < element["lat"]) &&(element['lat'] < lat1 + 0.001) && (lng1 - 0.001 < element["lng"]) && (element['lng'] < lng1 + 0.001)) {
new google.maps.Marker({
position: element,
map: map,
});
}
});
// new google.maps.Marker({
// position: loc[0],
// map: map
// });
// new google.maps.Marker({
// position: loc[1],
// map: map
// });
}
function Submit(inp) {
var dataEntered = retrieveData();
var readData = readingDataFromLocalStorage(dataEntered);
if (inp === 0) {
return Number(readData[0]);
}
else {
return Number(readData[1]);
}
}
//create
//retrieving data from form
function retrieveData() {
var lat = document.getElementById("lattitude").value;
var long = document.getElementById("longitude").value;
var arr = [lat, long];
return arr;
}
//Data in local storage
function readingDataFromLocalStorage(dataEntered) {
//storing data in local storage
var la = localStorage.setItem("lat", dataEntered[0]);
var lo = localStorage.setItem("long", dataEntered[1]);
//getting values from local to table
var la1 = localStorage.getItem("lat", la);
var lo1 = localStorage.getItem("long", lo);
var arr = [la1, lo1];
return arr;
}