Skip to main content
Version: 5.x
Supported on
Snapchat
Spectacles
Camera Kit Android
This feature may have limited compatibility and may not perform optimally.
Camera Kit iOS
This feature may have limited compatibility and may not perform optimally.
Camera Kit Web
This feature may have limited compatibility and may not perform optimally.

Snapchat Places API

Snapchat Places API for Lenses, which powers how different places interact in the Snapchat Map, offers Lens Developers a way to bringing the Snapchat map into a Lens. This will allow for developers to pull in data on places that are nearby them within a Lens.

Snapchat Places API module is available in APIs category of Lens Studio Asset Library;

alt text

Endpoints

This section documents the API endpoints of the Snapchat Places API for use with the Remote Service Module. This API can be used to get information from the Snapchat Map that users can interact with.

get_nearby_places

List Nearby Places given a location.

This will give you the place_id which you can use with other APIs to get more information.

lat and lng will automatically be filled in by the Lens to allow you to get nearby places from a user. Thus, you can get a list of nearby places like so:

Parameters

NameTypeDescription
latDoubleLatitude of the device. The default value is based on the user's location.
lngDoubleLongitude of the device. The default value is based on the user's location.
gps_accuracy_mDoubleHorizontal GPS accuracy of the device. The default is set to 65.
places_limitint32Maximum number of nearby place results to return. Default is 10.

If you set gps_accuracy to a value greater than 3000, then you may not return any venues. If you set value less than 3000, we will calculate the search radius by min(100m, req.radius + buffer), the buffer is 50 meters. If you don't set gps accuracy at all, we will use default radius of 65m.

Response

NameTypeDescription
nearby_placesNearbyPlaceMessage that stores relevant information for the place.

NearbyPlace provides the following information:

NameTypeDescription
place_idstringThe unique identifier for the place.
namestringLocalized name of the place.
rankint32Rank order of the place returned.
subtitlestringAdditional descriptive text for the place.
is_reportableboolIndicates if this place can be reported by users.
placeTypeEnumstringThe type of place it is (e.g. VENUE).
categoryIduuidThe ID of the category this place is under.
categoryNamestringThe name of the category this place is under.

Example

function onReceiveNearbyPlaces(isError, places) {
// Get the names and id of nearby places
places.nearbyPlaces.map((place) => {
print(place.name + ' ' + place.placeId);
});
}

ApiModule.get_nearby_places(null, null, null, null, onReceiveNearbyPlaces);

get_places_profile

Renders the metadata needed to build Place Listings.

This will give you some of the basic data of a multiple places simultaneously, such as its opening hours, address, and phone numbers.

Parameters

NameTypeDescription
place_idsStringList of place_ids for which to retrieve place listings data.
localeStringOptional: Locale set in the request; if not in the header, defaults to acceptHeader.

Response

NameTypeDescription
place_profilesPlaceProfileList of PlaceProfile metadata respective to the IDs passed. Order is not maintained.

Example

You can get the opening hours of nearby places using the place_profile.

function onReceiveNearbyPlaces(isError, places) {
const listOfPlaceIds = JSON.stringify(
places.nearbyPlaces.map((p) => p.placeId)
);
ApiModule.get_places_profile(
listOfPlaceIds,
null,
function (isError, placeProfiles) {
print(JSON.stringify(placeProfiles));
}
);
}

ApiModule.get_nearby_places(null, null, null, null, onReceiveNearbyPlaces);

get_place

Renders the complete metadata associated with the place.

You can use this API to get as much information as possible on a single place, including latitude and longitude.

Parameters

NameTypeDescription
place_idStringplace_id for which to retrieve place listings data.

Response

NameTypeDescription
placePlacePlace metadata.

Examples

You can get detailed information on the highest ranked nearby place like so:

function onReceiveNearbyPlaces(isError, places) {
ApiModule.get_place(
places.nearbyPlaces[0].placeId,
function (isError, placeMetadata) {
print(JSON.stringify(placeMetadata));
}
);
}

ApiModule.get_nearby_places(null, null, null, null, onReceiveNearbyPlaces);

You can get latitude and longitude information for each place like so:

function onReceiveNearbyPlaces(response) {
try {
print('Full Response: ' + response.bodyAsString());

let places = response.bodyAsJson();

if (places && Array.isArray(places.nearbyPlaces)) {
places.nearbyPlaces.forEach((place) => {
ApiModule.get_place(place.placeId, function (isError, response) {
if (isError) {
print(`Error fetching metadata for ${place.name}`);
return;
}

const placeMetadata = response.bodyAsJson();
print(`Metadata for ${place.name}: ${JSON.stringify(placeMetadata)}`);

if (
placeMetadata.place &&
placeMetadata.place.geometry &&
placeMetadata.place.geometry.centroid
) {
const latitude = placeMetadata.place.geometry.centroid.lat;
const longitude = placeMetadata.place.geometry.centroid.lng;
print(
`Coordinates for ${place.name}: Latitude: ${latitude}, Longitude: ${longitude}`
);
} else {
print(`Coordinates not found for ${place.name}`);
}
});
});
} else {
print('No nearby places found or nearbyPlaces is undefined.');
}
} catch (error) {
print('Error parsing places: ' + error.message);
}
}
Was this page helpful?
Yes
No