# Maps by Google and Apple

![](https://689802330-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAn5scXl2uqUJUOqkJo%2F-LAn5wecEraNWaG7Ig2g%2F-LAn677ZOECqv4ieaDz4%2Fmap-%E2%9C%95-fig-1.png?generation=1524497161272408\&alt=media)

## Choose Your Provider

For iOS, you have the option to choose between Apple Maps or Google Maps. On Android, only Google Maps is available. Google Maps provides more custom style options from different map types to coloring and exposing or hiding map features.

## Properties

### Add Google Maps API Key

You can live-test your app without adding your unique Google Maps API keys, but you need to add them if you want to download or publish your app.&#x20;

#### Generate a Google Maps API Key

To generate your personal Google Maps API key, you need to:

1. Create a Google Cloud project for your app.
2. Create a billing account or enable billing for the project.
3. Click **Enable** to enable the Maps SDK for Android or Maps SDK for iOS. &#x20;
4. Select **Enable all Google Maps APIs for this project**.\
   ![](https://689802330-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUe3rgJfvQYLrpDR1HfWv%2Fuploads%2FgaZqd3YuPeSynaduTH4z%2FGoogle%20Maps%20API%202.png?alt=media\&token=b2178346-854c-4888-aa31-76e5520b91ca)
5. Copy the provided API key.&#x20;

{% hint style="info" %}
**Note:** If you close this pop pup message without copying your API key

1. Navigate to **APIs & Services**.
2. Select **Credentials** from the left side menu.
3. Click **SHOW KEY**.<br>

   <figure><img src="https://689802330-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUe3rgJfvQYLrpDR1HfWv%2Fuploads%2F6eaM57tZ8mVmf6K1yVHe%2FGoogle%20Maps%20API%20show%20key%202.png?alt=media&#x26;token=c06d389d-b47f-4807-9620-cd672726ef40" alt=""><figcaption></figcaption></figure>

{% endhint %}

For more detailed instructions, please see here: [Google Maps Platform: Set up your Google Cloud project](https://developers.google.com/maps/documentation/android-sdk/cloud-setup).

#### Add Google Maps API Key to Thunkable&#x20;

Once you've generated your Google Maps API keys, you can add them to your Thunkable project. Click the gear icon at the top of the components tree on your project's designer tab to access your [Project Settings](https://docs.thunkable.com/snap-to-place/projects/settings). Scroll to the **Google Map Settings** section and paste your Android and iOS API keys into the corresponding fields.&#x20;

<div align="left"><img src="https://689802330-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAn5scXl2uqUJUOqkJo%2F-MLIH7cr1AgSfnvIgJNM%2F-MLITG8Kf67DYx5Ihn7N%2Fmapapikeys.png?alt=media&#x26;token=f3ab46c8-a12a-4418-8808-cbc40ca61d1b" alt=""></div>

### Map

| Property  | Description                                                      | Data Type |
| --------- | ---------------------------------------------------------------- | --------- |
| Latitude  | Co-ordinate of the map's center on the north-south axis          | Number    |
| Longitude | Co-ordinate of the map's center on the east-west axis            | Number    |
| Zoom      | Zoom level between -15 (most zoomed out) and 15 (most zoomed in) | Number    |

### Layout

| Property | Description                    | Data Type  |
| -------- | ------------------------------ | ---------- |
| Height   | Height of Map in pixels        | Number     |
| Width    | Width of Map in pixels         | Number     |
| Visible  | Set whether the Map is visible | True/False |

### **Style**

| **Property**  | Description                                                                             | Data Type        |
| ------------- | --------------------------------------------------------------------------------------- | ---------------- |
| Border Width  | Width of border around Map in pixels                                                    | Number           |
| Border Radius | Radius of corners of border on Mapr in degrees                                          | Number           |
| Border Color  | Color of border (only visible if border width > 0)                                      | Color            |
| Border Style  | Set whether border style is solid, dotted or dashed  (only visible if border width > 0) | Select from menu |

There are a number of `Advanced` properties available to help you add custom styling to your map. Below are the most popular.

| Property                                              | Description                                                                                                                                                                                                                                                   |
| ----------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Map Type `Advanced`                                   | Default (`standard`); `standard` is the classic map style; `satellite` displays only satellite imagery; `hybrid` shows roads and features layered over satellite imagery; `terrain` shows physical terrain overlay on top of a classic map (Google Maps only) |
| Custom Map Style String (Google Maps Only) `Advanced` | Accepts a JSON string imported from the [Google Maps API styling wizard](https://mapstyle.withgoogle.com/). Map Type must be set to `standard` and provider must be set to `google`.                                                                          |
| Shows Traffic `Advanced`                              | Default (`false`); if `true`, shows real-time traffic overlay on the map                                                                                                                                                                                      |

### Edit Map size

For more information on sizing in your app, please see our [introduction here​](https://docs.thunkable.com/~/edit/primary/thunkable-cross-platform/2-create/intro-to-sizing)

| Property | Description                                                                                                                                                                                                                     |
| -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Height   | Default (`Fill container`); Four options: 1) `Fit contents` which auto-sizes to the content size or 2) `Fill container` which auto-sizes to the container 3) `Relative size` in percent of Screen, 4) `Absolute size` in pixels |
| Width    | Default (`Fit container`); Four options: 1) `Fit contents` which auto-sizes to the content size or 2) `Fill container` which auto-sizes to the container 3) `Relative size` in percent of Screen, 4) `Absolute size` in pixels  |

### Add Spacing

For more information on adding spacing in your app, please see our [introduction here](https://docs.thunkable.com/snap-to-place/intro-to-spacing)

To find the spacing properties, you'll have to select the `Advanced` tab

| Property           | Description                                                                                                                                                                                                 |
| ------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Margin `Advanced`  | Default (`none`); Margin is the space outside of the border of a component; You can set space on the `top`, `bottom`, `right` or `left` of the component in both pixels or percent of Screen                |
| Padding `Advanced` | Default (`none`); Padding is the space between the contents and the border of a component; You can set space on the `top`, `bottom`, `right` or `left` of the component in both pixels or percent of Screen |

## Blocks

### Events

The map has several events. You can trigger actions to happen when these events occur.

#### On Map Ready

This event happens when the Map has loaded in your app.&#x20;

This is a good time to add any markers, polylines or polygons to your app that you want the user to see as soon as your app opens.

![](https://689802330-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAn5scXl2uqUJUOqkJo%2F-MXm-VzBm17M2Y4a2Gq1%2F-MXm1Kgoc6OY6Tr1vFSc%2FScreen%20Shot%202021-04-08%20at%204.10.55%20PM.png?alt=media\&token=98424ab5-52e1-4f9a-8e24-d6f909a61a27)

#### On User Location Change

This event happens when the location of the user changes. It returns the **coordinate** object.\
You can use [object blocks](https://docs.thunkable.com/snap-to-place/objects) to get the properties of the coordinate object.

The **coordinate** object has the following properties:

**{**\
&#x20;   **target:** Numeric ID for your app\
&#x20;   **coordinate:{**\
&#x20;         **latitude:** latitude of point selected\
&#x20;         **longitude:** longitude of point selected \
&#x20;   **}**\
&#x20;   **position:{**\
&#x20;         **x:** x-position of selected point on the Map component\
&#x20;         **y:** x-position of selected point on the Map component\
&#x20;   **}**\
**}**

![](https://689802330-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAn5scXl2uqUJUOqkJo%2F-MXm-VzBm17M2Y4a2Gq1%2F-MXm1meHqHyzV12FT5fs%2FScreen%20Shot%202021-04-08%20at%204.12.54%20PM.png?alt=media\&token=af26b655-0e01-4391-aaab-ff58ef376e1f)

#### On Press

This event happens when the user taps on the Map.

![](https://689802330-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAn5scXl2uqUJUOqkJo%2F-MBpVvP62WZTrcDW9OCp%2F-MBpWh2aLcgKOenP4ip0%2Fmaponpressnew.png?alt=media\&token=68212f24-6dae-4ba6-aaa0-8b7558622ccb)

| Output name | Output value                                        | Data Type |
| ----------- | --------------------------------------------------- | --------- |
| Latitude    | Latitude of selected position                       | Number    |
| Longitude   | Longitude of selected position                      | Number    |
| position X  | X Co-ordinate of selected position on map component | Number    |
| position Y  | Y Co-ordinate of selected position on map component | Number    |

#### On Long Press

This event happens when the user presses on the map for a longer period of time.

![](https://689802330-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAn5scXl2uqUJUOqkJo%2F-MBpVvP62WZTrcDW9OCp%2F-MBpX5SwUBCTqQdkx-LA%2Fmaponlongpressnew.png?alt=media\&token=fd5fac3c-abdb-4f3b-babf-a0fa3ec6d351)

| Output name | Output value                                        | Data Type |
| ----------- | --------------------------------------------------- | --------- |
| Latitude    | Latitude of selected position                       | Number    |
| Longitude   | Longitude of selected position                      | Number    |
| position X  | X Co-ordinate of selected position on map component | Number    |
| position Y  | Y Co-ordinate of selected position on map component | Number    |

#### On Marker Press

This event happens when the user clicks on a Marker that is on the Map.

The **On Marker Press** block returns an **event** object. This is an object which can be used with [object blocks.](https://docs.thunkable.com/snap-to-place/objects)&#x20;

The **event** object has the following properties:

{\
&#x20;   **latitude:** latitude of the selected Marker\
&#x20;   **longitude**: longitude of the selected Marker\
}

![](https://689802330-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAn5scXl2uqUJUOqkJo%2F-MXm-VzBm17M2Y4a2Gq1%2F-MXm1zIvNR7KuH81lFQI%2FScreen%20Shot%202021-04-08%20at%204.13.46%20PM.png?alt=media\&token=8a2e0eda-7fec-42dd-a11d-ae3a55d8064a)

### Functions

#### Add Marker

Adds a generic map marker to your map at the specified latitude/longitude.

![](https://689802330-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUe3rgJfvQYLrpDR1HfWv%2Fuploads%2FpbPio20WkaF0CoSFlvw5%2Fmapaddmarker.png?alt=media\&token=f1dc723c-d2ed-494c-83c9-b20e8d0a6ae4)

This block takes the following inputs:

<table><thead><tr><th width="150">Input</th><th width="310.2755707033053">Description</th><th>Data Type</th></tr></thead><tbody><tr><td>Latitude</td><td>Latitude of marker's position</td><td>Number between -90 and 90</td></tr><tr><td>Longitude</td><td>Longitude of marker's position</td><td>Number between -90 and 90</td></tr><tr><td>Title</td><td>Title of marker (displayed when marker is clicked)</td><td>Text</td></tr><tr><td>Description</td><td>Description of marker (displayed when marker is clicked)</td><td>Text</td></tr><tr><td>Pin Color</td><td>Color of marker</td><td>Color</td></tr></tbody></table>

#### Add Icon Marker

Adds a marker of a selected image to your map at the specified latitude/longitude

![](https://689802330-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUe3rgJfvQYLrpDR1HfWv%2Fuploads%2FyJ8yvD9BO2tytQIYw8QF%2Fimage.png?alt=media\&token=a082b0ca-98ae-43d0-a10a-3e84bea0be85)

This block takes the following inputs:

<table><thead><tr><th width="150">Input</th><th width="310.2755707033053">Description</th><th>Data Type</th></tr></thead><tbody><tr><td>Latitude</td><td>Latitude of marker's position</td><td>Number between -90 and 90</td></tr><tr><td>Longitude</td><td>Longitude of marker's position</td><td>Number between -90 and 90</td></tr><tr><td>Title</td><td>Title of marker (displayed when marker is clicked)</td><td>Text</td></tr><tr><td>Description</td><td>Description of marker (displayed when marker is clicked)</td><td>Text</td></tr><tr><td>Icon</td><td>Image to use as marker</td><td>Dropdown menu (select <a href="../projects/assets#uploading-and-managing-assets">asset</a>)</td></tr></tbody></table>

#### Add Polyline

Add a polyline to your map. This is an outline that connects several points on your map.

This block takes the following inputs:

| Input        | Description                                                    | Data Type                                                                                                                                                                                                                      |
| ------------ | -------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| Coordinate   | List of points to draw a line between. List can be any length. | List of [objects](https://docs.thunkable.com/snap-to-place/objects). Each object must have the properties `latitude` and `longitude.` Latitude and Longitude must be [numbers](https://docs.thunkable.com/snap-to-place/math). |
| Stroke Width | Width of polyline                                              | Number                                                                                                                                                                                                                         |
| Stroke Color | Color of polyline                                              | Color                                                                                                                                                                                                                          |

&#x20;These blocks:

![](https://689802330-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAn5scXl2uqUJUOqkJo%2F-MhxvXEJm7h40PjzRKJD%2F-Mhy4okD_eftTIerq0g9%2Fpolyline.png?alt=media\&token=f579e715-7a2e-4d9d-853a-0d17330460d5)

Will produce this polyline:

![](https://689802330-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAn5scXl2uqUJUOqkJo%2F-MhxvXEJm7h40PjzRKJD%2F-Mhy58yzvFvX_psLd3Kp%2Fpolyline.jpeg?alt=media\&token=e1c725d0-4435-4a40-88a3-43e11bc77d61)

Note that polylines won't automatically create a closed shape. You would need to add a forth object with the properties `latitude: 37` and `longitude: -122` to the `coordinate` input of the `addPolyline` block above to close this triangular polyline.

#### Add Polygon

Add a polygon to your map. This is a solid shape that connects several points on your map.

This block takes the following inputs:

| Input        | Description                                                    | Data Type                                                                                                                                                                                                                      |
| ------------ | -------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| Coordinate   | List of points to draw a line between. List can be any length. | List of [objects](https://docs.thunkable.com/snap-to-place/objects). Each object must have the properties `latitude` and `longitude.` Latitude and Longitude must be [numbers](https://docs.thunkable.com/snap-to-place/math). |
| Stroke Width | Width of outline                                               | Number                                                                                                                                                                                                                         |
| Stroke Color | Color of outline (Only visible if Stroke Width > 0)            | Color                                                                                                                                                                                                                          |
| Fill Color   | Color of polygon shape                                         | Color                                                                                                                                                                                                                          |

These blocks:

![](https://689802330-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAn5scXl2uqUJUOqkJo%2F-MhxvXEJm7h40PjzRKJD%2F-Mhy9HhbkeQFkmLS8kJz%2FScreen%20Shot%202021-08-25%20at%205.33.46%20PM.png?alt=media\&token=77c3f71b-f467-40e9-9d94-9cdafc30acd5)

Will produce this polygon:

![](https://689802330-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAn5scXl2uqUJUOqkJo%2F-MhxvXEJm7h40PjzRKJD%2F-Mhy9QseqtxUd7nnLZbA%2Fpolygon.jpeg?alt=media\&token=54b6fba6-76c3-437c-b5e5-9905bf551f74)

Note that the polygon outline will automatically connect the first and last points in the list of coordinates.

#### Delete Markers, Polylines and Polygons

You can use the **deleteAllMarkers** block to delete all [markers](#add-marker) from your app.

![](https://689802330-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAn5scXl2uqUJUOqkJo%2F-MXm-VzBm17M2Y4a2Gq1%2F-MXm10ct3lOYpPRdD8po%2FScreen%20Shot%202021-04-08%20at%204.09.33%20PM.png?alt=media\&token=48143f80-7f3e-4990-991f-449cb4a511ac)

You can use the **deleteAllPolylines** block to delete all [polylines](#add-polyline) from your app.

![](https://689802330-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAn5scXl2uqUJUOqkJo%2F-MXm-VzBm17M2Y4a2Gq1%2F-MXm17SaYyiu0711unnj%2FScreen%20Shot%202021-04-08%20at%204.10.01%20PM.png?alt=media\&token=7bcc282a-4122-4d66-8442-f17dac47bd7a)

You can use the **deleteAllPolygons** block to delete all [polygons](#add-polygon) from your app.

![](https://689802330-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAn5scXl2uqUJUOqkJo%2F-MXm-VzBm17M2Y4a2Gq1%2F-MXm13zRGmlULSvuTgj5%2FScreen%20Shot%202021-04-08%20at%204.09.45%20PM.png?alt=media\&token=911220bd-475b-4825-a6ca-10cdb53c3080)

### Properties

Set and get [properties](#properties) of the Map component.

#### Latitude

![](https://689802330-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAn5scXl2uqUJUOqkJo%2F-MhxvXEJm7h40PjzRKJD%2F-MhyC5-qvpaeW8iL1ZcC%2Flat.jpg?alt=media\&token=d03f2745-6e92-467e-b08d-6d2a4cee7d72)

#### Longitude

![](https://689802330-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAn5scXl2uqUJUOqkJo%2F-MhxvXEJm7h40PjzRKJD%2F-MhyCDjG83HgeVZRK4T3%2Flong.jpg?alt=media\&token=3ec26f51-d814-4675-87ad-d022ca740bd3)

#### Zoom

![](https://689802330-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAn5scXl2uqUJUOqkJo%2F-MhxvXEJm7h40PjzRKJD%2F-MhyCL8l3suFr7zm0X6C%2Fzoom.png?alt=media\&token=880780ca-a06b-48af-9625-d2b8b8454ef8)

#### Computed Height

![](https://689802330-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAn5scXl2uqUJUOqkJo%2F-MhxvXEJm7h40PjzRKJD%2F-MhyCTOFXHLv9IManILL%2Fmapheight.png?alt=media\&token=d8cb1682-cdeb-4152-b1fa-4c9d84fe9db2)

Returns the height of the Map on the device screen in pixels.

#### Computed Width

![](https://689802330-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAn5scXl2uqUJUOqkJo%2F-MhxvXEJm7h40PjzRKJD%2F-MhyCWxN88OYHtqySm8a%2Fmapwidth.png?alt=media\&token=dd8f1853-a38a-4d8c-b401-61bf73e01a46)

Returns the width of the Map on the device screen in pixels.

#### Visible

![](https://689802330-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LAn5scXl2uqUJUOqkJo%2F-MhxvXEJm7h40PjzRKJD%2F-MhyC_uZIwolImSxNysL%2Fmapvisible.png?alt=media\&token=5f692abe-b3af-4764-bade-b30b1bb075be)

## See Also

You can pair the Map component with a [Location Sensor](https://docs.thunkable.com/snap-to-place/location-sensor). This helps you show content relevant to the user's location.

These blocks will set the map's latitude and longitude to show the user's location once the map is ready:

![](https://689802330-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUe3rgJfvQYLrpDR1HfWv%2Fuploads%2Ftr30HhuHDv5B8TeMaDJt%2Fmaponready.png?alt=media\&token=47e2d1b2-d597-4f05-ae32-be96514a7804)
