I have a JavaScript function that checks for latitude and longitude upon page load. It calls a method on the page with those coordinates. Within the method, I utilize RegisterClientScriptBlock to define numerous variables and then generate a string of JavaScript code to showcase a map using those variables. The map does load, but I encounter an issue where the expected variables are undefined.
<script type="text/javascript">
function validateAndLoadMap() {
if (navigator.geolocation) {
var progressPanel = $get('progress');
progressPanel.style.display = '';
var mapPanel = $get('map');
mapPanel.style.display = 'none';
navigator.geolocation.getCurrentPosition(function (position) {
// Access the location data
PageMethods.SetSession(position.coords.latitude, position.coords.longitude, displayMap);
});
}
}
function displayMap(result) {
eval(result);
}
</script>
[WebMethod]
public static string SetSession(string latitudeValue, string longitudeValue)
{
// Perform necessary actions, use RegisterClientScriptBlock to set array variables like latitudes and longitudes
return "showMap(" + latitudeValue + "," + longitudeValue + ");";
}