The LinkedIn API does not expose a dedicated "Geo endpoint" for retrieving arbitrary geographic coordinates or location data. Instead, location information is embedded within user profile fields such as location, which returns structured name-value pairs like country and city codes. To access this data, developers must request the appropriate OAuth 2.0 scopes during authentication and parse the resulting JSON response from the standard /me or /people/~ endpoints.
Understanding Location Data in LinkedIn Profiles
When integrating with the LinkedIn REST API, it is crucial to distinguish between explicit geolocation services and profile metadata. Unlike mapping APIs that provide latitude and longitude, LinkedIn stores location primarily as textual identifiers for professional context. The platform uses ISO 3166-1 alpha-2 country codes and specific city names rather than raw GPS coordinates. This design choice protects user privacy while still allowing applications to filter candidates or content by region. Developers often assume a direct endpoint exists for querying global geography because many modern APIs offer such features. However, LinkedIn’s architecture ties location data strictly to authenticated user profiles or company pages. There is no public endpoint that allows you to look up the geographic position of a random city or convert an address to coordinates without first having access to a user’s profile. If your application requires precise mapping, you must rely on third-party geocoding services using the text data retrieved from LinkedIn, rather than expecting LinkedIn to provide the coordinates directly.Required OAuth Scopes
Accessing any personal profile data, including location, requires explicit permission from the user. You cannot retrieve this information anonymously or with basic read-only scopes meant for public posts. The primary scope required isr_liteprofile, which grants access to the minimal set of profile fields. For more detailed location history or education-based locations, the r_basicprofile scope was historically used but has largely been superseded by r_liteprofile in newer API versions (v2).
If you are building an application that needs to display where a user is based, you must ensure your OAuth 2.0 authorization request includes these scopes. Without them, the API will return null values or omit the location field entirely in the response body. Always test your integration with a sandbox account to verify that the permissions are correctly granted before deploying to production.
Implementing the Profile Request
To retrieve location data, you send an HTTP GET request to the/me endpoint. This endpoint returns a JSON object containing various profile attributes. The structure includes a nested location object, which contains name and country fields. The country field typically provides the two-letter ISO code, while the name field offers the full city and state/province string.
Here is a conceptual example of how to structure the request using cURL. Ensure you replace <ACCESS_TOKEN> with a valid bearer token obtained through the OAuth flow.
curl -X GET "https://api.linkedin.com/v2/me" \
-H "Authorization: Bearer <ACCESS_TOKEN>" \
-H "LinkedIn-Version: 202303" \
-H "X-Restli-Protocol-Version: 2.0.0"
The response will resemble the following structure. Note that if the user has not set a location, the location key may be absent or empty.
{
"id": "...",
"firstName": {...},
"lastName": {...},
"localizedFirstName": "...",
"localizedLastName": "...",
"headline": "...",
"location": {
"country": {
"code": "US"
},
"name": "San Francisco Bay Area"
}
}
Always handle cases where the location data is missing gracefully. Many users leave their location blank for privacy reasons, so your application should have fallback logic to display "Location not specified" rather than crashing or showing default values.
Parsing and Utilizing the Data
Once you receive the JSON payload, parse thelocation.country.code and location.name fields according to your application’s needs. For filtering purposes, comparing the country code against a list of target markets is efficient and reliable. For displaying human-readable addresses, use the name field directly.
It is important to remember that LinkedIn does not provide real-time geolocation tracking. The location data reflects what the user has manually entered into their profile settings. It is not updated via GPS when the user logs in. Therefore, do not treat this data as a substitute for active location services. If your use case requires knowing where a user is currently located for safety or logistical reasons, you must implement separate mobile or web-based geolocation features outside of the LinkedIn API integration.
For teams struggling with other common development hurdles, such as terminal encoding issues, you might find resources on Backspace not working properly with accents in Intellij's terminal helpful for maintaining a clean development environment while debugging API responses.
Frequently Asked Questions
Can I get latitude and longitude from LinkedIn?
No, the LinkedIn API does not provide latitude or longitude coordinates. It only supplies textual location data like city names and country codes. You must use a separate geocoding service to convert these text strings into map coordinates if needed.Why is my location field returning null?
This usually happens because the user has not set a location in their profile or has set it to private. Additionally, ensure your OAuth token includes ther_liteprofile scope. Without proper permissions, sensitive profile fields are hidden.