Skip to main content

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: fully supported
  • SPECS: not supported
  • Camera Kit Web: not supported
  • Camera Kit Mobile: not supported
  • SnapchatFully supported
  • SPECSNot supported
  • Camera Kit WebNot supported — Remote Service Enabled Lenses can't run in Camera Kit
  • Camera Kit MobileNot supported — Remote Service Enabled Lenses can't run in Camera Kit

Platform details

  • Snapchat — Fully supported.

  • SPECS — Not supported.

  • Camera Kit Web — Not supported — Remote Service Enabled Lenses can't run in Camera Kit.

  • Camera Kit Mobile — Not supported — Remote Service Enabled Lenses can't run in Camera Kit.

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 (for example, VENUE).
categoryIdUUIDThe ID of the category this place is under.
categoryNamestringThe name of the category this place is under.

Example

ApiModule.get_nearby_places({ parameters: {} })
.then((response) => {
const places = response.bodyAsJson();
// Get the names and id of nearby places
places.nearbyPlaces.forEach((place) => {
print(place.name + ' ' + place.placeId);
});
})
.catch((error) => {
print(error);
});

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.

ApiModule.get_nearby_places({ parameters: {} })
.then((response) => {
const places = response.bodyAsJson();
const listOfPlaceIds = JSON.stringify(
places.nearbyPlaces.map((p) => p.placeId)
);
return ApiModule.get_places_profile({
parameters: { place_ids: listOfPlaceIds },
});
})
.then((response) => {
const placeProfiles = response.bodyAsJson();
print(JSON.stringify(placeProfiles));
})
.catch((error) => {
print(error);
});

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:

ApiModule.get_nearby_places({ parameters: {} })
.then((response) => {
const places = response.bodyAsJson();
return ApiModule.get_place({
parameters: { place_id: places.nearbyPlaces[0].placeId },
});
})
.then((response) => {
const placeMetadata = response.bodyAsJson();
print(JSON.stringify(placeMetadata));
})
.catch((error) => {
print(error);
});

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({ parameters: { place_id: place.placeId } })
.then((response) => {
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}`);
}
})
.catch(() => {
print(`Error fetching metadata for ${place.name}`);
});
});
} else {
print('No nearby places found or nearbyPlaces is undefined.');
}
} catch (error) {
print('Error parsing places: ' + error.message);
}
}

ApiModule.get_nearby_places({ parameters: {} })
.then(onReceiveNearbyPlaces)
.catch((error) => {
print(error);
});