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,16 +84,16 @@ 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) {
92
+
if(application.ios) {
95
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;
@@ -107,83 +105,119 @@ if (platform.isIOS) {
107
105
108
106
## Adding the MapView
109
107
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.
108
+
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
109
112
110
```
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
158
+
`coordinateTapped` | Fires when a coordinate is tapped on the map
159
+
`coordinateLongPress` | Fires when a coordinate is long-pressed on the map
160
+
`markerSelect` | Fires when a marker is selected
161
+
`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
162
`markerBeginDragging` | Fires when a marker begins dragging
156
-
`markerDrag` | Fires repeatedly while a marker is being dragged
157
163
`markerEndDragging` | Fires when a marker ends dragging
158
-
`markerInfoWindowTapped` | Fired on tapping Marker Info Window
159
-
`cameraChanged` | Fired after the camera has changed
160
-
`cameraMove` | Fired while the camera is moving
164
+
`markerDrag` | Fires repeatedly while a marker is being dragged
165
+
`markerInfoWindowTapped` | Fires when a marker's info window is tapped
166
+
`cameraChanged` | Fires after the camera has changed
167
+
`cameraMove` | Fires repeatedly while the camera is moving
168
+
169
+
## Native Map Object
170
+
171
+
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)
172
+
173
+
## UI Settings
174
+
175
+
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`
180
+
`indoorLevelPickerEnabled` | Whether the indoor level picker is enabled or not: `Boolean`
181
+
`mapToolbarEnabled` | ****Android only**** Whether the map toolbar is enabled or not: `Boolean`
182
+
`myLocationButtonEnabled` | Whether the 'My Location' button is enabled or not: `Boolean`
183
+
`rotateGesturesEnabled` | Whether the compass is enabled or not: `Boolean`
184
+
`scrollGesturesEnabled` | Whether map scroll gestures are enabled or not: `Boolean`
185
+
`tiltGesturesEnabled` | Whether map tilt gestures are enabled or not: `Boolean`
186
+
`zoomGesturesEnabled` | Whether map zoom gestures are enabled or not: `Boolean`
187
+
`zoomControlsEnabled` | ****Android only**** Whether map zoom controls are enabled or not: `Boolean`
161
188
189
+
## Styling
190
+
191
+
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/)).
192
+
193
+
### Angular
194
+
195
+
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 }`.
162
196
163
-
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) )
197
+
## Basic Example
164
198
165
199
```
166
200
// /app/main-page.js
167
201
168
202
var mapsModule = require("nativescript-google-maps-sdk");
`compassEnabled` | boolean - Whether the compass is enabled/disabled
210
-
`indoorLevelPickerEnabled` | boolean - Whether the indoor level picker is enabled/disabled
211
-
`mapToolbarEnabled` | boolean - Whether the indoor level picker is enabled/disabled ******Android only******
212
-
`myLocationButtonEnabled` | boolean - Whether the my-location button is enabled/disabled
213
-
`rotateGesturesEnabled` | boolean - Whether the compass is enabled/disabled
214
-
`scrollGesturesEnabled` | boolean - Whether scroll gestures are enabled/disabled
215
-
`tiltGesturesEnabled` | boolean - Whether tilt gestures are enabled/disabled
216
-
`zoomControlsEnabled` | boolean - Whether the zoom controls are enabled/disabled ******Android only******
217
-
`zoomGesturesEnabled` | boolean - Whether zoom gestures are enabled/disabled
218
-
219
-
220
-
## Styling
221
-
Use `gMap.setStyle(style);` to change the map styling.
222
-
223
-
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 }`.
224
-
225
-
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/).
226
-
227
237
## Custom Info Windows (Beta)
228
238
229
-
To customize the marker info windows, define a template in your view like so:
239
+
To use custom marker info windows, define a template in your view like so:
230
240
231
241
```
232
-
<!-- /app/main-page.xml -->
233
-
<Page
234
-
xmlns="http://www.nativescript.org/tns.xsd"
235
-
xmlns:maps="nativescript-google-maps-sdk"
236
-
>
242
+
<!-- /app/main-page.xml -->
243
+
<Page
244
+
xmlns="http://www.nativescript.org/tns.xsd"
245
+
xmlns:maps="nativescript-google-maps-sdk"
246
+
>
237
247
<GridLayout>
238
248
<maps:mapView mapReady="onMapReady">
239
249
<!-- Default Info Window Template -->
@@ -259,20 +269,20 @@ To customize the marker info windows, define a template in your view like so:
259
269
</Page>
260
270
```
261
271
262
-
If a marker has the `infoWindowTemplate` property set like so:
272
+
...and set the `infoWindowTemplate` property like so:
263
273
264
274
```
265
275
var marker = new mapsModule.Marker();
266
276
marker.infoWindowTemplate = 'testWindow';
267
277
```
268
278
269
-
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.
279
+
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.
270
280
271
-
***Known Issue* - External Images fail to show in iOS info windows (local Images work fine)
281
+
***Known issue:* remote images fail to display in iOS info windows (local images work fine)
272
282
273
-
## Using with Angular
283
+
## Usage with Angular
274
284
275
-
See angular demo code included [here](https://github.com/dapriett/nativescript-google-maps-sdk/tree/master/ng-demo)
285
+
See Angular demo code included [here](https://github.com/dapriett/nativescript-google-maps-sdk/tree/master/ng-demo)
276
286
277
287
```
278
288
// /app/map-example.component.ts
@@ -303,14 +313,16 @@ export class MapExampleComponent {
303
313
```
304
314
# Angular 8 Support
305
315
306
-
If you are using Angular 8, there is a temporary change to the `@ViewChild` directive, this will not be needed in Angular 9.
316
+
If you are using Angular 8, there is a temporary fix needed for the `@ViewChild` directive, and will not be needed in Angular 9:
307
317
308
-
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))
312
324
313
-
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)
325
+
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