Jaafarsa commited on
Commit
07eb26a
·
verified ·
1 Parent(s): 86e3dcc

fix the error for google map, if not working please use other map like petal map

Browse files
Files changed (1) hide show
  1. index.html +55 -84
index.html CHANGED
@@ -103,53 +103,43 @@
103
  </section>
104
 
105
  <script>
106
- // Initialize Food Map
107
  function initFoodMap() {
108
  if (navigator.geolocation) {
109
  navigator.geolocation.getCurrentPosition(function(position) {
110
- const userLatLng = {
111
- lat: position.coords.latitude,
112
- lng: position.coords.longitude
113
- };
114
-
115
- const map = new google.maps.Map(document.getElementById("foodMap"), {
116
- center: userLatLng,
117
  zoom: 12,
118
- styles: [
119
- { elementType: "geometry", stylers: [{ color: "#242f3e" }] },
120
- { elementType: "labels.text.stroke", stylers: [{ color: "#242f3e" }] },
121
- { elementType: "labels.text.fill", stylers: [{ color: "#746855" }] }
122
- ]
123
  });
124
-
125
  // Add user location marker
126
- new google.maps.Marker({
127
- position: userLatLng,
128
  map: map,
129
  title: "Your Location",
130
- icon: {
131
- url: "https://maps.google.com/mapfiles/ms/icons/blue-dot.png"
132
- }
133
  });
134
 
135
  // Sample food rescue locations
136
  const foodLocations = [
137
  {
138
- position: { lat: userLatLng.lat + 0.008, lng: userLatLng.lng + 0.008 },
139
  title: "Bakery Delight",
140
  offer: "Bread Surprise Bag",
141
  price: "$3.99",
142
  distance: "0.3 mi"
143
  },
144
  {
145
- position: { lat: userLatLng.lat + 0.015, lng: userLatLng.lng - 0.01 },
146
  title: "GreenEats",
147
  offer: "Vegetarian Lunch Box",
148
  price: "$4.80",
149
  distance: "0.7 mi"
150
  },
151
  {
152
- position: { lat: userLatLng.lat - 0.02, lng: userLatLng.lng - 0.015 },
153
  title: "Ocean Bites",
154
  offer: "Sushi Surprise Pack",
155
  price: "$6.00",
@@ -159,92 +149,78 @@
159
 
160
  // Add food location markers
161
  foodLocations.forEach(location => {
162
- const marker = new google.maps.Marker({
163
  position: location.position,
164
  map: map,
165
  title: location.title,
166
- icon: {
167
- url: "https://maps.google.com/mapfiles/ms/icons/red-dot.png"
168
- }
169
  });
170
 
171
- const infoWindow = new google.maps.InfoWindow({
172
  content: `
173
- <div class="text-gray-800">
174
  <h3 class="font-bold">${location.title}</h3>
175
  <p>Offer: ${location.offer}</p>
176
  <p>Price: ${location.price}</p>
177
  <p>Distance: ${location.distance}</p>
178
  </div>
179
- `
 
180
  });
181
 
182
- marker.addListener("click", () => {
183
- infoWindow.open(map, marker);
184
  });
185
  });
186
- });
187
  }
188
  }
189
-
190
- // Call initFoodMap when page loads
191
- document.addEventListener('DOMContentLoaded', function() {
192
  initMap();
193
  initFoodMap();
194
- });
195
- </script>
196
- <script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&libraries=places"></script>
197
- <script>
198
- // Initialize Google Map
 
 
199
  function initMap() {
200
  if (navigator.geolocation) {
201
  navigator.geolocation.getCurrentPosition(function(position) {
202
- const userLatLng = {
203
- lat: position.coords.latitude,
204
- lng: position.coords.longitude
205
- };
206
-
207
- const map = new google.maps.Map(document.getElementById("productsMap"), {
208
- center: userLatLng,
209
  zoom: 12,
210
- styles: [
211
- { elementType: "geometry", stylers: [{ color: "#242f3e" }] },
212
- { elementType: "labels.text.stroke", stylers: [{ color: "#242f3e" }] },
213
- { elementType: "labels.text.fill", stylers: [{ color: "#746855" }] },
214
- {
215
- featureType: "poi",
216
- elementType: "labels.text.fill",
217
- stylers: [{ color: "#d59563" }]
218
- }
219
- ]
220
  });
221
-
222
  // Add user location marker
223
- new google.maps.Marker({
224
- position: userLatLng,
225
  map: map,
226
  title: "Your Location",
227
- icon: {
228
- url: "https://maps.google.com/mapfiles/ms/icons/blue-dot.png"
229
- }
230
  });
231
 
232
- // Sample product locations (in a real app, these would come from your database)
233
  const products = [
234
  {
235
- position: { lat: userLatLng.lat + 0.01, lng: userLatLng.lng + 0.01 },
236
  title: "Handwoven Macrame",
237
  price: "$45",
238
  distance: "0.5 mi"
239
  },
240
  {
241
- position: { lat: userLatLng.lat + 0.02, lng: userLatLng.lng - 0.01 },
242
  title: "Ceramic Mug Set",
243
  price: "$28",
244
  distance: "1.2 mi"
245
  },
246
  {
247
- position: { lat: userLatLng.lat - 0.03, lng: userLatLng.lng - 0.02 },
248
  title: "Leather Wallet",
249
  price: "$75",
250
  distance: "2.5 mi"
@@ -253,30 +229,29 @@
253
 
254
  // Add product markers
255
  products.forEach(product => {
256
- const marker = new google.maps.Marker({
257
  position: product.position,
258
  map: map,
259
  title: product.title,
260
- icon: {
261
- url: "https://maps.google.com/mapfiles/ms/icons/green-dot.png"
262
- }
263
  });
264
 
265
- const infoWindow = new google.maps.InfoWindow({
266
  content: `
267
- <div class="text-gray-800">
268
  <h3 class="font-bold">${product.title}</h3>
269
  <p>Price: ${product.price}</p>
270
  <p>Distance: ${product.distance}</p>
271
  </div>
272
- `
 
273
  });
274
 
275
- marker.addListener("click", () => {
276
- infoWindow.open(map, marker);
277
  });
278
  });
279
- });
280
  }
281
  }
282
 
@@ -967,13 +942,9 @@ const chatMessages = document.getElementById('chatMessages');
967
  script.defer = true;
968
  document.head.appendChild(script);
969
  }
970
-
971
- // Load maps when page is ready
972
- if (document.readyState === 'complete') {
973
- loadGoogleMaps();
974
- } else {
975
- window.addEventListener('load', loadGoogleMaps);
976
- }
977
  // Cart functionality
978
  let cart = JSON.parse(localStorage.getItem('cart')) || [];
979
 
 
103
  </section>
104
 
105
  <script>
 
106
  function initFoodMap() {
107
  if (navigator.geolocation) {
108
  navigator.geolocation.getCurrentPosition(function(position) {
109
+ const userPosition = [position.coords.longitude, position.coords.latitude];
110
+
111
+ const map = new AMap.Map("foodMap", {
112
+ viewMode: "3D",
 
 
 
113
  zoom: 12,
114
+ center: userPosition,
115
+ mapStyle: "amap://styles/dark"
 
 
 
116
  });
 
117
  // Add user location marker
118
+ new AMap.Marker({
119
+ position: userPosition,
120
  map: map,
121
  title: "Your Location",
122
+ icon: "https://webapi.amap.com/theme/v1.3/markers/n/mark_b.png"
 
 
123
  });
124
 
125
  // Sample food rescue locations
126
  const foodLocations = [
127
  {
128
+ position: [userPosition[0] + 0.008, userPosition[1] + 0.008],
129
  title: "Bakery Delight",
130
  offer: "Bread Surprise Bag",
131
  price: "$3.99",
132
  distance: "0.3 mi"
133
  },
134
  {
135
+ position: [userPosition[0] + 0.015, userPosition[1] - 0.01],
136
  title: "GreenEats",
137
  offer: "Vegetarian Lunch Box",
138
  price: "$4.80",
139
  distance: "0.7 mi"
140
  },
141
  {
142
+ position: [userPosition[0] - 0.02, userPosition[1] - 0.015],
143
  title: "Ocean Bites",
144
  offer: "Sushi Surprise Pack",
145
  price: "$6.00",
 
149
 
150
  // Add food location markers
151
  foodLocations.forEach(location => {
152
+ const marker = new AMap.Marker({
153
  position: location.position,
154
  map: map,
155
  title: location.title,
156
+ icon: "https://webapi.amap.com/theme/v1.3/markers/n/mark_r.png"
 
 
157
  });
158
 
159
+ const infoWindow = new AMap.InfoWindow({
160
  content: `
161
+ <div class="text-gray-800 p-2">
162
  <h3 class="font-bold">${location.title}</h3>
163
  <p>Offer: ${location.offer}</p>
164
  <p>Price: ${location.price}</p>
165
  <p>Distance: ${location.distance}</p>
166
  </div>
167
+ `,
168
+ offset: new AMap.Pixel(0, -30)
169
  });
170
 
171
+ marker.on('click', () => {
172
+ infoWindow.open(map, marker.getPosition());
173
  });
174
  });
175
+ });
176
  }
177
  }
178
+ // Initialize both maps
179
+ function initMaps() {
 
180
  initMap();
181
  initFoodMap();
182
+ }
183
+
184
+ document.addEventListener('DOMContentLoaded', initMaps);
185
+ </script>
186
+ <script src="https://webapi.amap.com/maps?v=2.0&key=YOUR_PETAL_MAP_KEY"></script>
187
+ <script>
188
+ // Initialize Petal Map
189
  function initMap() {
190
  if (navigator.geolocation) {
191
  navigator.geolocation.getCurrentPosition(function(position) {
192
+ const userPosition = [position.coords.longitude, position.coords.latitude];
193
+
194
+ const map = new AMap.Map("productsMap", {
195
+ viewMode: "3D",
 
 
 
196
  zoom: 12,
197
+ center: userPosition,
198
+ mapStyle: "amap://styles/dark"
 
 
 
 
 
 
 
 
199
  });
 
200
  // Add user location marker
201
+ new AMap.Marker({
202
+ position: userPosition,
203
  map: map,
204
  title: "Your Location",
205
+ icon: "https://webapi.amap.com/theme/v1.3/markers/n/mark_b.png"
 
 
206
  });
207
 
208
+ // Sample product locations
209
  const products = [
210
  {
211
+ position: [userPosition[0] + 0.01, userPosition[1] + 0.01],
212
  title: "Handwoven Macrame",
213
  price: "$45",
214
  distance: "0.5 mi"
215
  },
216
  {
217
+ position: [userPosition[0] + 0.02, userPosition[1] - 0.01],
218
  title: "Ceramic Mug Set",
219
  price: "$28",
220
  distance: "1.2 mi"
221
  },
222
  {
223
+ position: [userPosition[0] - 0.03, userPosition[1] - 0.02],
224
  title: "Leather Wallet",
225
  price: "$75",
226
  distance: "2.5 mi"
 
229
 
230
  // Add product markers
231
  products.forEach(product => {
232
+ const marker = new AMap.Marker({
233
  position: product.position,
234
  map: map,
235
  title: product.title,
236
+ icon: "https://webapi.amap.com/theme/v1.3/markers/n/mark_r.png"
 
 
237
  });
238
 
239
+ const infoWindow = new AMap.InfoWindow({
240
  content: `
241
+ <div class="text-gray-800 p-2">
242
  <h3 class="font-bold">${product.title}</h3>
243
  <p>Price: ${product.price}</p>
244
  <p>Distance: ${product.distance}</p>
245
  </div>
246
+ `,
247
+ offset: new AMap.Pixel(0, -30)
248
  });
249
 
250
+ marker.on('click', () => {
251
+ infoWindow.open(map, marker.getPosition());
252
  });
253
  });
254
+ });
255
  }
256
  }
257
 
 
942
  script.defer = true;
943
  document.head.appendChild(script);
944
  }
945
+ // Initialize map when page loads
946
+ window.initMap = initMap;
947
+ document.addEventListener('DOMContentLoaded', initMap);
 
 
 
 
948
  // Cart functionality
949
  let cart = JSON.parse(localStorage.getItem('cart')) || [];
950