You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -15,68 +15,66 @@ This is a cross-platform (iOS & Android) Nativescript plugin for the [Google Map
15
15
16
16
Prerequisites
17
17
===
18
-
*iOS* - Cocoapods is [installed](https://guides.cocoapods.org/using/getting-started.html#getting-started)
18
+
**iOS** - [Cocoapods](https://guides.cocoapods.org/using/getting-started.html#getting-started) must be installed.
19
19
20
-
*Android* - Latest Google Play services SDK[installed](https://developer.android.com/sdk/installing/adding-packages.html)
20
+
**Android** - The latest version of the [Google Play Services SDK](https://developer.android.com/sdk/installing/adding-packages.html) must be installed.
21
21
22
-
*Google Maps API Key* - Go to the [Google Developers Console](https://console.developers.google.com), create a project, and enable the `Google Maps Android API` and `Google Maps SDK for iOS` APIs. Then under credentials, create an API key.
22
+
**Google Maps API Key** - Visit the [Google Developers Console](https://console.developers.google.com), create a project, and enable the `Google Maps Android API` and `Google Maps SDK for iOS` APIs. Then, under credentials, create an API key.
23
23
24
24
Installation
25
25
===
26
26
27
-
## Install the plugin using the NativeScript CLI tooling
27
+
Install the plugin using the NativeScript CLI tooling:
28
28
29
29
```
30
30
tns plugin add nativescript-google-maps-sdk
31
31
```
32
32
33
-
Setup Google Maps API
33
+
Setup
34
34
===
35
35
36
36
See demo code included [here](https://github.com/dapriett/nativescript-google-maps-sdk/tree/master/demo)
37
37
38
-
Live Demo[here](https://tinyurl.com/m7ndp7u)
38
+
See a live demo[here](https://tinyurl.com/m7ndp7u)
39
39
40
-
## Setup Android API Key
41
-
42
-
40
+
## Configure API Key for Android
43
41
44
42
### Nativescript < 4
45
43
46
-
First copy over the template string resource files for Android
44
+
Start by copying the necessary template resource files in to the Android app resources folder:
Next modify the file at `app/App_Resources/Android/values/nativescript_google_maps_api.xml`, uncomment `nativescript_google_maps_api_key` string and replace `PUT_API_KEY_HERE` with your api key.
49
+
Next, modify your `app/App_Resources/Android/values/nativescript_google_maps_api.xml` file by uncommenting the `nativescript_google_maps_api_key` string, and replace `PUT_API_KEY_HERE` with the API key you created earlier.
52
50
53
-
Then, in your `AndroidManifest.xml` located at `app/App_Resources/Android/AndroidManifest.xml` insert into your `<application>` tags
51
+
Finally, modify your `app/App_Resources/Android/AndroidManifest.xml`file by inserting the following in between the `<application>` tags:
Next modify the file at `app/App_Resources/Android/src/main/res/values/nativescript_google_maps_api.xml`, uncomment `nativescript_google_maps_api_key` string and replace `PUT_API_KEY_HERE` with your api key.
67
+
Next, modify your `app/App_Resources/Android/src/main/res/values/nativescript_google_maps_api.xml` file by uncommenting the `nativescript_google_maps_api_key` string, and replace `PUT_API_KEY_HERE` with the API key you created earlier.
70
68
71
-
Then, in your `AndroidManifest.xml` located at `app/App_Resources/Android/src/main/AndroidManifest.xml`insert into your `<application>` tags
69
+
Finally, modify your `app/App_Resources/Android/src/main/AndroidManifest.xml`file by inserting the following in between your `<application>` tags:
The plugin will default to latest available version of the Android `play-services-maps`SDK. If you need to change the version, you can add a projectext property `googlePlayServicesVersion` like so:
77
+
The plugin will default to the latest available version of the Google Play Services SDK for Android. If you need to change the version, you can add a `project.ext` property,`googlePlayServicesVersion`, like so:
80
78
81
79
```
82
80
// /app/App_Resources/Android/app.gradle
@@ -86,105 +84,144 @@ project.ext {
86
84
}
87
85
```
88
86
89
-
## Setup iOS API Key
87
+
## Configure API Key for iOS
90
88
91
-
In the main script of your app `app.js`, use the following to add the API key (providing your key in place of `PUT_API_KEY_HERE`)
89
+
In your `app.js`, use the following code to add your API key (replace `PUT_API_KEY_HERE` with the API key you created earlier):
92
90
93
91
```
94
-
if(application.ios) {
95
-
GMSServices.provideAPIKey("PUT_API_KEY_HERE");
92
+
if(application.ios) {
93
+
GMSServices.provideAPIKey("PUT_API_KEY_HERE");
96
94
}
97
95
```
98
-
If you are using Angular, you need to modify the`app.module.ts` as follows:
96
+
If you are using Angular, modify your`app.module.ts` as follows:
99
97
```
100
98
import * as platform from "platform";
101
99
declare var GMSServices: any;
100
+
102
101
....
102
+
103
103
if (platform.isIOS) {
104
-
GMSServices.provideAPIKey("PUT_API_KEY_HERE");
104
+
GMSServices.provideAPIKey("PUT_API_KEY_HERE");
105
105
}
106
106
```
107
107
108
108
## Adding the MapView
109
109
110
-
Modify your view by adding the namespace `xmlns:maps="nativescript-google-maps-sdk"` to your page, then using the `<maps:mapView />` tag to create the MapView.
110
+
Modify your view by adding the `xmlns:maps="nativescript-google-maps-sdk"`namespace to your `<Page>` tag, then use the `<maps:mapView />` tag to create the MapView:
111
111
112
112
```
113
-
<!-- /app/main-page.xml -->
114
-
<Page
115
-
xmlns="http://www.nativescript.org/tns.xsd"
116
-
xmlns:maps="nativescript-google-maps-sdk"
117
-
>
118
-
<GridLayout>
119
-
<maps:mapView latitude="{{ latitude }}" longitude="{{ longitude }}" mapAnimationsEnabled="{{ mapAnimationsEnabled }}"
`mapReady` | Called when Google Map is ready for use
151
-
`coordinateTapped` | Fires when coordinate is clicked on map
152
-
`coordinateLongPress` | Fires when coordinate is "longpressed"
153
-
`markerSelect` | Fires whenever a marker is selected
154
-
`shapeSelect` | Fires whenever a shape (`Circle`, `Polygon`, `Polyline`) is clicked. You must explicity configure `shape.clickable = true;`on your shapes.
`mapReady`| Fires when the MapView is ready for use
161
+
`coordinateTapped` | Fires when a coordinate is tapped on the map
162
+
`coordinateLongPress` | Fires when a coordinate is long-pressed on the map
163
+
`markerSelect` | Fires when a marker is selected
164
+
`shapeSelect` | Fires when a shape (e.g., `Circle`, `Polygon`, `Polyline`) is selected *(Note: you must explicity configure `shape.clickable = true;`for this event to fire)*
155
165
`markerBeginDragging` | Fires when a marker begins dragging
156
-
`markerDrag` | Fires repeatedly while a marker is being dragged
157
166
`markerEndDragging` | Fires when a marker ends dragging
158
-
`markerInfoWindowTapped` | Fired on tapping Marker Info Window
159
-
`myLocationTapped` | Fired when the 'My Location' button is tapped
160
-
`cameraChanged` | Fired after the camera has changed
161
-
`cameraMove` | Fired while the camera is moving
167
+
`markerDrag` | Fires repeatedly while a marker is being dragged
168
+
`myLocationTapped` | Fires when the 'My Location' button is tapped
169
+
`markerInfoWindowTapped` | Fires when a marker's info window is tapped
170
+
`cameraChanged` | Fires after the camera has changed
171
+
`cameraMove` | Fires repeatedly while the camera is moving
172
+
173
+
## Native Map Object
174
+
175
+
The MapView's `gMap` property gives you access to the platform's native map object–––consult the appropriate SDK reference on how to use it: [iOS](https://developers.google.com/maps/documentation/ios-sdk/reference/interface_g_m_s_map_view) | [Android](https://developers.google.com/android/reference/com/google/android/gms/maps/GoogleMap)
176
+
177
+
## UI Settings
178
+
179
+
You can adjust the map's UI settings after the `mapReady` event has fired by configuring the following properties on `mapView.settings`:
`compassEnabled` | Whether the compass is enabled or not: `Boolean`
184
+
`indoorLevelPickerEnabled` | Whether the indoor level picker is enabled or not: `Boolean`
185
+
`mapToolbarEnabled` | ****Android only**** Whether the map toolbar is enabled or not: `Boolean`
186
+
`myLocationButtonEnabled` | Whether the 'My Location' button is enabled or not: `Boolean`
187
+
`rotateGesturesEnabled` | Whether the compass is enabled or not: `Boolean`
188
+
`scrollGesturesEnabled` | Whether map scroll gestures are enabled or not: `Boolean`
189
+
`tiltGesturesEnabled` | Whether map tilt gestures are enabled or not: `Boolean`
190
+
`zoomGesturesEnabled` | Whether map zoom gestures are enabled or not: `Boolean`
191
+
`zoomControlsEnabled` | ****Android only**** Whether map zoom controls are enabled or not: `Boolean`
163
192
164
-
The property `gMap` gives you access to the raw platform Map Object - see their SDK references for how to use them ( [iOS](https://developers.google.com/maps/documentation/ios-sdk/reference/interface_g_m_s_map_view) | [Android](https://developers.google.com/android/reference/com/google/android/gms/maps/GoogleMap) )
193
+
## Styling
194
+
195
+
Use `gMap.setStyle(style);` to set the map's styling ([Google Maps Style Reference](https://developers.google.com/maps/documentation/android-api/style-reference) | [Styling Wizard](https://mapstyle.withgoogle.com/)).
196
+
197
+
### Angular
198
+
199
+
Use `this.mapView.setStyle(<Style>JSON.parse(this.styles));` inside of the `onMapReady` event handler. In this example, `this.mapView` is the `MapView` object and `this.styles` is a reference to a JSON file that was created using the [Styling Wizard](https://mapstyle.withgoogle.com/). The `<Style>` type was imported from the plugin as `{ Style }`.
200
+
201
+
## Basic Example
165
202
166
203
```
167
204
// /app/main-page.js
168
205
169
206
var mapsModule = require("nativescript-google-maps-sdk");
`compassEnabled` | boolean - Whether the compass is enabled/disabled
211
-
`indoorLevelPickerEnabled` | boolean - Whether the indoor level picker is enabled/disabled
212
-
`mapToolbarEnabled` | boolean - Whether the indoor level picker is enabled/disabled ******Android only******
213
-
`myLocationButtonEnabled` | boolean - Whether the 'My Location' button is enabled/disabled
214
-
`rotateGesturesEnabled` | boolean - Whether the compass is enabled/disabled
215
-
`scrollGesturesEnabled` | boolean - Whether scroll gestures are enabled/disabled
216
-
`tiltGesturesEnabled` | boolean - Whether tilt gestures are enabled/disabled
217
-
`zoomControlsEnabled` | boolean - Whether the zoom controls are enabled/disabled ******Android only******
218
-
`zoomGesturesEnabled` | boolean - Whether zoom gestures are enabled/disabled
219
-
220
-
221
-
## Styling
222
-
Use `gMap.setStyle(style);` to change the map styling.
223
-
224
-
For Angular map styling, use `this.mapView.setStyle(<Style>JSON.parse(this.styles));` inside of the `onMapReady` function. In this example `this.mapView` is the imported `MapView` from the plugin and `this.styles` is a reference to a json file that was created using the link below. The `<Style>` was also imported from the plugin as `{ Style }`.
225
-
226
-
For map styles, see [Google Maps Style Reference](https://developers.google.com/maps/documentation/android-api/style-reference) and the [Styling Wizard](https://mapstyle.withgoogle.com/).
227
-
228
241
## Custom Info Windows (Beta)
229
242
230
-
To customize the marker info windows, define a template in your view like so:
243
+
To use custom marker info windows, define a template in your view like so:
231
244
232
245
```
233
-
<!-- /app/main-page.xml -->
234
-
<Page
235
-
xmlns="http://www.nativescript.org/tns.xsd"
236
-
xmlns:maps="nativescript-google-maps-sdk"
237
-
>
246
+
<!-- /app/main-page.xml -->
247
+
<Page
248
+
xmlns="http://www.nativescript.org/tns.xsd"
249
+
xmlns:maps="nativescript-google-maps-sdk"
250
+
>
238
251
<GridLayout>
239
252
<maps:mapView mapReady="onMapReady">
240
253
<!-- Default Info Window Template -->
@@ -260,20 +273,20 @@ To customize the marker info windows, define a template in your view like so:
260
273
</Page>
261
274
```
262
275
263
-
If a marker has the `infoWindowTemplate` property set like so:
276
+
...and set the `infoWindowTemplate` property like so:
264
277
265
278
```
266
279
var marker = new mapsModule.Marker();
267
280
marker.infoWindowTemplate = 'testWindow';
268
281
```
269
282
270
-
This will use the template with that key. If it's not set then it'll use the default custom template if set, overwise the standard info window.
283
+
This will configure the marker to use the info window template with the given key. If no template with that key is found, then it will use the default info window template.
271
284
272
-
***Known Issue* - External Images fail to show in iOS info windows (local Images work fine)
285
+
***Known issue:* remote images fail to display in iOS info windows (local images work fine)
273
286
274
-
## Using with Angular
287
+
## Usage with Angular
275
288
276
-
See angular demo code included [here](https://github.com/dapriett/nativescript-google-maps-sdk/tree/master/ng-demo)
289
+
See Angular demo code included [here](https://github.com/dapriett/nativescript-google-maps-sdk/tree/master/ng-demo)
277
290
278
291
```
279
292
// /app/map-example.component.ts
@@ -304,14 +317,16 @@ export class MapExampleComponent {
304
317
```
305
318
# Angular 8 Support
306
319
307
-
If you are using Angular 8, there is a temporary change to the `@ViewChild` directive, this will not be needed in Angular 9.
320
+
If you are using Angular 8, there is a temporary fix needed for the `@ViewChild` directive, and will not be needed in Angular 9:
308
321
309
-
For now use this instead: `@ViewChild("MapView", {static: false}) mapView: ElementRef;`
# Clustering Support (Issue [#57](https://github.com/dapriett/nativescript-google-maps-sdk/issues/57))
313
328
314
-
There is a seperate plugin in development thanks to [@naderio](https://github.com/naderio) - see [nativescript-google-maps-utils](https://github.com/naderio/nativescript-google-maps-utils)
329
+
There is a seperate plugin in development thanks to [@naderio](https://github.com/naderio): see [nativescript-google-maps-utils](https://github.com/naderio/nativescript-google-maps-utils).
0 commit comments