Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
155 changes: 142 additions & 13 deletions apps/sim/blocks/blocks/google_maps.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { GoogleMapsIcon } from '@/components/icons'
import type { BlockConfig, BlockMeta } from '@/blocks/types'
import { IntegrationType } from '@/blocks/types'
import { AuthMode, IntegrationType } from '@/blocks/types'

export const GoogleMapsBlock: BlockConfig = {
type: 'google_maps',
Expand All @@ -11,6 +11,7 @@ export const GoogleMapsBlock: BlockConfig = {
docsLink: 'https://docs.sim.ai/integrations/google_maps',
category: 'tools',
integrationType: IntegrationType.Search,
authMode: AuthMode.ApiKey,
bgColor: '#FFFFFF',
icon: GoogleMapsIcon,

Expand All @@ -26,6 +27,7 @@ export const GoogleMapsBlock: BlockConfig = {
{ label: 'Get Directions', id: 'directions' },
{ label: 'Distance Matrix', id: 'distance_matrix' },
{ label: 'Search Places', id: 'places_search' },
{ label: 'Nearby Places', id: 'places_nearby' },
{ label: 'Place Details', id: 'place_details' },
{ label: 'Get Elevation', id: 'elevation' },
{ label: 'Get Timezone', id: 'timezone' },
Expand All @@ -51,7 +53,7 @@ export const GoogleMapsBlock: BlockConfig = {
hideWhenHosted: true,
condition: { field: 'operation', value: 'speed_limits', not: true },
},
// API Key — always visible for Speed Limits (deprecated API, no hosted key support)
// API Key — always visible for Speed Limits (Asset Tracking-license restricted, no hosted key support)
{
id: 'apiKey',
title: 'API Key',
Expand Down Expand Up @@ -196,6 +198,15 @@ export const GoogleMapsBlock: BlockConfig = {
condition: { field: 'operation', value: 'places_search' },
mode: 'advanced',
},
// Radius — required and always visible for Nearby Places (mandatory search area)
{
id: 'radius',
title: 'Radius (meters)',
type: 'short-input',
placeholder: 'Search radius in meters, up to 50000 (e.g., 5000)',
condition: { field: 'operation', value: 'places_nearby' },
required: { field: 'operation', value: 'places_nearby' },
},
{
id: 'placeType',
title: 'Place Type',
Expand All @@ -222,9 +233,37 @@ export const GoogleMapsBlock: BlockConfig = {
{ label: 'Bus Station', id: 'bus_station' },
{ label: 'Parking', id: 'parking' },
],
condition: { field: 'operation', value: ['places_search', 'places_nearby'] },
mode: 'advanced',
},
{
id: 'pageToken',
title: 'Page Token',
type: 'short-input',
placeholder: 'Token from a previous search (wait ~2s before using it)',
condition: { field: 'operation', value: 'places_search' },
mode: 'advanced',
},
{
id: 'maxResultCount',
title: 'Max Results',
type: 'short-input',
placeholder: 'Maximum number of results (1-20, defaults to 20)',
condition: { field: 'operation', value: 'places_nearby' },
mode: 'advanced',
},
{
id: 'rankPreference',
title: 'Rank By',
type: 'dropdown',
options: [
{ label: 'Popularity', id: 'POPULARITY' },
{ label: 'Distance', id: 'DISTANCE' },
],
value: () => 'POPULARITY',
condition: { field: 'operation', value: 'places_nearby' },
mode: 'advanced',
},

{
id: 'placeId',
Expand Down Expand Up @@ -269,6 +308,18 @@ export const GoogleMapsBlock: BlockConfig = {
rows: 2,
mode: 'advanced',
},
{
id: 'speedUnits',
title: 'Speed Units',
type: 'dropdown',
options: [
{ label: 'KPH', id: 'KPH' },
{ label: 'MPH', id: 'MPH' },
],
value: () => 'KPH',
condition: { field: 'operation', value: 'speed_limits' },
mode: 'advanced',
},

{
id: 'addressToValidate',
Expand All @@ -284,7 +335,7 @@ export const GoogleMapsBlock: BlockConfig = {
title: 'Region Code',
type: 'short-input',
placeholder: 'ISO country code (e.g., US, CA, GB)',
condition: { field: 'operation', value: 'validate_address' },
condition: { field: 'operation', value: ['validate_address', 'places_nearby'] },
mode: 'advanced',
},
{
Expand Down Expand Up @@ -332,6 +383,22 @@ export const GoogleMapsBlock: BlockConfig = {
condition: { field: 'operation', value: 'geolocate' },
mode: 'advanced',
},
{
id: 'homeMobileCountryCode',
title: 'Home Mobile Country Code',
type: 'short-input',
placeholder: 'Home network MCC (e.g., 310)',
condition: { field: 'operation', value: 'geolocate' },
mode: 'advanced',
},
{
id: 'homeMobileNetworkCode',
title: 'Home Mobile Network Code',
type: 'short-input',
placeholder: 'Home network MNC (e.g., 410)',
condition: { field: 'operation', value: 'geolocate' },
mode: 'advanced',
},
{
id: 'wifiAccessPoints',
title: 'WiFi Access Points',
Expand All @@ -356,23 +423,23 @@ export const GoogleMapsBlock: BlockConfig = {
title: 'Latitude',
type: 'short-input',
placeholder: '37.4224764',
condition: { field: 'operation', value: ['air_quality', 'pollen', 'solar'] },
required: { field: 'operation', value: ['air_quality', 'pollen', 'solar'] },
condition: { field: 'operation', value: ['air_quality', 'pollen', 'solar', 'places_nearby'] },
required: { field: 'operation', value: ['air_quality', 'pollen', 'solar', 'places_nearby'] },
},
{
id: 'aqLongitude',
title: 'Longitude',
type: 'short-input',
placeholder: '-122.0842499',
condition: { field: 'operation', value: ['air_quality', 'pollen', 'solar'] },
required: { field: 'operation', value: ['air_quality', 'pollen', 'solar'] },
condition: { field: 'operation', value: ['air_quality', 'pollen', 'solar', 'places_nearby'] },
required: { field: 'operation', value: ['air_quality', 'pollen', 'solar', 'places_nearby'] },
},
{
id: 'languageCode',
title: 'Language Code',
type: 'short-input',
placeholder: 'Language code (e.g., en, es)',
condition: { field: 'operation', value: ['air_quality', 'pollen'] },
condition: { field: 'operation', value: ['air_quality', 'pollen', 'places_nearby'] },
mode: 'advanced',
},

Expand Down Expand Up @@ -412,6 +479,18 @@ export const GoogleMapsBlock: BlockConfig = {
type: 'short-input',
placeholder: 'Language code (e.g., en, es, fr, de)',
mode: 'advanced',
condition: {
field: 'operation',
value: [
'geocode',
'reverse_geocode',
'directions',
'distance_matrix',
'places_search',
'place_details',
'timezone',
],
},
},
{
id: 'region',
Expand All @@ -432,6 +511,7 @@ export const GoogleMapsBlock: BlockConfig = {
'google_maps_geocode',
'google_maps_geolocate',
'google_maps_place_details',
'google_maps_places_nearby',
'google_maps_places_search',
'google_maps_pollen',
'google_maps_reverse_geocode',
Expand Down Expand Up @@ -490,7 +570,8 @@ export const GoogleMapsBlock: BlockConfig = {

let radius: number | undefined
if (params.radius) {
radius = Number.parseInt(params.radius, 10)
const parsedRadius = Number.parseInt(params.radius, 10)
radius = Number.isNaN(parsedRadius) ? undefined : parsedRadius
}

let placeIds: string[] | undefined
Expand Down Expand Up @@ -549,6 +630,24 @@ export const GoogleMapsBlock: BlockConfig = {
params.plantsDescription === 'true' || params.plantsDescription === true
}

let maxResultCount: number | undefined
if (params.maxResultCount) {
const parsedMaxResultCount = Number.parseInt(params.maxResultCount, 10)
maxResultCount = Number.isNaN(parsedMaxResultCount) ? undefined : parsedMaxResultCount
}

let homeMobileCountryCode: number | undefined
if (params.homeMobileCountryCode) {
const parsed = Number.parseInt(params.homeMobileCountryCode, 10)
homeMobileCountryCode = Number.isNaN(parsed) ? undefined : parsed
}

let homeMobileNetworkCode: number | undefined
if (params.homeMobileNetworkCode) {
const parsed = Number.parseInt(params.homeMobileNetworkCode, 10)
homeMobileNetworkCode = Number.isNaN(parsed) ? undefined : parsed
}

return {
...rest,
address,
Expand All @@ -567,10 +666,15 @@ export const GoogleMapsBlock: BlockConfig = {
considerIp,
days,
plantsDescription,
maxResultCount,
homeMobileCountryCode,
homeMobileNetworkCode,
requiredQuality: params.requiredQuality || undefined,
type: params.placeType || undefined,
includedTypes: params.placeType ? [params.placeType] : undefined,
avoid: params.avoid || undefined,
radioType: params.radioType || undefined,
units: operation === 'speed_limits' ? params.speedUnits || undefined : params.units,
}
},
},
Expand All @@ -593,6 +697,12 @@ export const GoogleMapsBlock: BlockConfig = {
locationBias: { type: 'string', description: 'Location bias for search' },
radius: { type: 'string', description: 'Search radius in meters' },
placeType: { type: 'string', description: 'Place type filter' },
pageToken: { type: 'string', description: 'Token to fetch the next page of place results' },
maxResultCount: { type: 'string', description: 'Maximum number of nearby results to return' },
rankPreference: {
type: 'string',
description: 'Nearby results ranking (POPULARITY, DISTANCE)',
},
placeId: { type: 'string', description: 'Google Place ID' },
fields: { type: 'string', description: 'Fields to retrieve' },
units: { type: 'string', description: 'Unit system' },
Expand All @@ -601,18 +711,30 @@ export const GoogleMapsBlock: BlockConfig = {
path: { type: 'string', description: 'Pipe-separated lat,lng coordinates' },
interpolate: { type: 'boolean', description: 'Interpolate points along road' },
placeIds: { type: 'string', description: 'Pipe-separated Place IDs for speed limits' },
speedUnits: { type: 'string', description: 'Units for speed limit results (KPH, MPH)' },
addressToValidate: { type: 'string', description: 'Address to validate' },
regionCode: { type: 'string', description: 'ISO country code for address' },
regionCode: { type: 'string', description: 'ISO country code for address or nearby search' },
locality: { type: 'string', description: 'City name hint' },
enableUspsCass: { type: 'boolean', description: 'Enable USPS CASS validation' },
considerIp: { type: 'boolean', description: 'Use IP for geolocation' },
homeMobileCountryCode: { type: 'string', description: 'Home network mobile country code' },
homeMobileNetworkCode: { type: 'string', description: 'Home network mobile network code' },
radioType: { type: 'string', description: 'Radio type (lte, gsm, etc.)' },
carrier: { type: 'string', description: 'Carrier name' },
wifiAccessPoints: { type: 'string', description: 'WiFi access points JSON' },
cellTowers: { type: 'string', description: 'Cell towers JSON' },
aqLatitude: { type: 'string', description: 'Latitude for air quality, pollen, or solar' },
aqLongitude: { type: 'string', description: 'Longitude for air quality, pollen, or solar' },
languageCode: { type: 'string', description: 'Language code for air quality or pollen' },
aqLatitude: {
type: 'string',
description: 'Latitude for air quality, pollen, solar, or nearby search',
},
aqLongitude: {
type: 'string',
description: 'Longitude for air quality, pollen, solar, or nearby search',
},
languageCode: {
type: 'string',
description: 'Language code for air quality, pollen, or nearby search',
},
days: { type: 'string', description: 'Number of pollen forecast days (1-5)' },
plantsDescription: { type: 'boolean', description: 'Include detailed plant descriptions' },
requiredQuality: { type: 'string', description: 'Minimum solar imagery quality' },
Expand Down Expand Up @@ -807,5 +929,12 @@ export const GoogleMapsBlockMeta = {
content:
'# Calculate Travel Distances\n\nGet a distance matrix from an origin to multiple destinations.\n\n## Steps\n1. Set the Origin and provide Destinations as a pipe-separated list (e.g., "New York, NY|Boston, MA").\n2. Choose Travel Mode and Units; optionally set features to Avoid.\n3. Run the Distance Matrix operation.\n4. Read each row for distance and duration to each destination.\n\n## Output\nA table of destinations sorted by travel time or distance, each with distance text and duration text. Useful for picking the nearest option or planning routes.',
},
{
name: 'find-places-nearby',
description:
'Find places of a given type within a radius of a coordinate, ranked by popularity or distance, without needing a text query.',
content:
"# Find Places Nearby\n\nDiscover places around a fixed point (e.g., a store, delivery stop, or event venue) by type and radius, without a free-text search.\n\n## Steps\n1. Set the Latitude/Longitude of the center point and a Radius (meters, up to 50000).\n2. Optionally constrain by Place Type (restaurant, hotel, pharmacy, etc.) and choose Rank By (Popularity or Distance).\n3. Set Max Results if you only need the top few.\n4. Run the Nearby Places operation.\n\n## Output\nA list of nearby places with name, address, coordinates, rating, number of ratings, open-now status, and business status, ordered per the chosen ranking. Use Place Details with a result's place ID for phone/website/hours.",
},
],
} as const satisfies BlockMeta
3 changes: 2 additions & 1 deletion apps/sim/tools/google_maps/elevation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export const googleMapsElevationTool: ToolConfig<
elevation: result.elevation,
lat: result.location.lat,
lng: result.location.lng,
resolution: result.resolution,
resolution: result.resolution ?? null,
},
}
},
Expand All @@ -100,6 +100,7 @@ export const googleMapsElevationTool: ToolConfig<
type: 'number',
description:
'Maximum distance between data points (meters) from which elevation was interpolated',
optional: true,
},
},
}
2 changes: 2 additions & 0 deletions apps/sim/tools/google_maps/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { googleMapsElevationTool } from '@/tools/google_maps/elevation'
import { googleMapsGeocodeTool } from '@/tools/google_maps/geocode'
import { googleMapsGeolocateTool } from '@/tools/google_maps/geolocate'
import { googleMapsPlaceDetailsTool } from '@/tools/google_maps/place_details'
import { googleMapsPlacesNearbyTool } from '@/tools/google_maps/places_nearby'
import { googleMapsPlacesSearchTool } from '@/tools/google_maps/places_search'
import { googleMapsPollenTool } from '@/tools/google_maps/pollen'
import { googleMapsReverseGeocodeTool } from '@/tools/google_maps/reverse_geocode'
Expand All @@ -22,6 +23,7 @@ export {
googleMapsGeocodeTool,
googleMapsGeolocateTool,
googleMapsPlaceDetailsTool,
googleMapsPlacesNearbyTool,
googleMapsPlacesSearchTool,
googleMapsPollenTool,
googleMapsReverseGeocodeTool,
Expand Down
Loading
Loading