I am currently facing some challenges while creating a map with markers using data from Google Sheet and leaflet. Despite my efforts, I have encountered a few bugs that are proving to be difficult to resolve:
- Group Filtering - Although I can successfully filter by group, only one marker is displayed for each selected group even when there are multiple data points within the same group. You can view the output in the attached photo https://i.stack.imgur.com/uGM8e.png.
- Marker Replacements - My intention was for the map to display markers corresponding to the selected group exclusively. However, if I select a group (e.g., Male) and then try to switch to another group (Female), the marker representing the previous group remains visible. Check out the issue illustrated here: https://i.stack.imgur.com/wrQsG.png.
Here is a glimpse of the sample data retrieved from Google Sheet https://i.stack.imgur.com/BXnll.png.
Presented below is an excerpt of my code:
function doGet(e) {
return HtmlService.createHtmlOutputFromFile('map');
}
function getAddress(group) {
var ss= SpreadsheetApp.getActiveSpreadsheet();
var groupSheet = ss.getSheetByName("Sheet1");
var getLastRow = groupSheet.getLastRow();
var return_array = [];
if (group === 'All'){
return groupSheet.getRange(2, 1, getLastRow - 1, 5).getValues();
} else {
for (var i = 2; i<= getLastRow; i++){
if (groupSheet.getRange(i,3).getValue() === group){
return_array.push(groupSheet.getRange(i,1,1,5).getValues());
}
}
return return_array;
}
}
HTML Structure
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Document</title>
<link rel="stylesheet" href="https://unpkg.com/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="741811151218110034455a435a45">[email protected]</a>/dist/leaflet.css"
integrity="sha512-xodZBNTC5n17Xt2atTPuE1HxjVMSvLVW9ocqUKLsCC5CXdbqCmblAshOMAS6/keqq/sMZMZ19scR4PsZChSR7A=="
crossorigin="" />
<script src="https://unpkg.com/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="036f6662656f667743322d342d32">[email protected]</a>/dist/leaflet.js"
integrity="sha512-XQoYMqMTK8LvdxXYG3nZ448hOEQiglfqkJs1NOQV44cWnUrBc8PkAOcXy20w0vlaXaVUearIOBhiXZ5V3ynxwA=="
crossorigin=""></script>
</head>
...Continued...
</style>
Your assistance in resolving these issues would be greatly appreciated!