I am getting an error only in android and I believe it has to do with an error "
android.os.NetworkOnMainThreadException" I have a location field that is added from the map manually. then later I try to add the location to another field in the same library in lat/long coordinates. It is failing on the call to the url but the url looks fine. similear calls seem to work in other libraries and I am thinking it is related to permissions but I have checked all permissions and can see no difference between libraries. The same script works fine in desktop.
// Get the address from LocationOnMap field
var address = entry().field("LocationOnMap").address;
//message("Address to geocode: " + address);
entry().set("debug1", address);
// Check if address field has content
if (address && address !== "") {
// Encode the address for URL
var encodedAddress = encodeURIComponent(address);
entry().set("debug2", encodedAddress);
// Build the Google Geocoding API URL
var apiKey = "*";
var url = "https:/" + "/" + "
maps.googleapis.com/maps/api/geocode/json?address=" + encodedAddress + "&key=" + apiKey;
// Store the URL in the "URL called" field
entry().set("URL called", url); message("DEBUG: URL being called: " + url);
message("DEBUG: About to make HTTP request...");
// Make the request to Google Geocoding API
var result = http().get(url);
// entry().set("debug2", result);
// message("DEBUG: HTTP request completed");
//message("DEBUG: HTTP response status: " + result.status);
// message("DEBUG: Raw response body: " + result.body);
var data = JSON.parse(result.body);
// message("DEBUG: Parsed data status: " + data.status);
// message("DEBUG: Number of results: " + (data.results ? data.results.length : "undefined"));
// Check if geocoding was successful
if (data.status === "OK" && data.results.length > 0) {
// message("DEBUG: Geocoding successful, processing first result...");
var location = data.results[0].geometry.location;
var latitude = location.lat;
var longitude = location.lng;
var formattedAddress = data.results[0].formatted_address;
// message("DEBUG: Latitude: " + latitude + ", Longitude: " + longitude);
// message("DEBUG: Formatted Address: " + formattedAddress);
// Create location object for Memento Database
var locationData = (latitude + "," + longitude);
entry().set("Location", locationData);
}
}