This question runs in a pre-configured Salesforce environment - no personal connection required.
Fetch geographic coordinates for a given city name using the OpenWeatherMap Geocoding API. Take a city name as parameter, make an HTTP callout to OpenWeatherMap Geocoding API, parse the latitude and longitude from the JSON response, and return coordinates in the format "lat,lon".
Use the OpenWeatherMap Geocoding API endpoint https://api.openweathermap.org/geo/1.0/direct?q={city}&limit=1&appid={API_KEY} to get location data. Extract the lat and lon fields from the first result and format as "lat,lon". Handle API errors and edge cases gracefully with appropriate error messages.
Examples:
Input: cityName = "London"
Output: "51.5074,-0.1278"
Explanation: London coordinates formatted as lat,lon
Input: cityName = "New York"
Output: "40.7128,-74.0060"
Explanation: New York coordinates formatted as lat,lon
Input: cityName = "NonExistentCity"
Output: "City not found"
Explanation: City not found in API response
Welcome to Lightning Challenge!
How It Works
- • Write your solution in the code editor
- • This challenge runs without connecting your own org
- • Submit to check if your solution passes
- • Use hints if you get stuck
Contest Alert
Contest runs July 1 - 31. Complete challenges to climb the leaderboard!
Only the 31 daily challenges shown during this contest count toward points. Earlier dailies don't carry over.