The problem is that I don't see any map and the error appears when subscribe runs. Does anyone know how to help me?
I tryied some ways btu they don't work
google-maps-into-ionic-2 or google maps from ionic native
Html:
<button (click)="getMapresults()"></button>
<ion-content>
<div id="mapid"></div>
</ion-content>
Trypescript:
import {Component, ViewChild, OnInit, NgZone} from '#angular/core';
import {NavController, Platform} from 'ionic-angular';
import {
Geolocation, GoogleMap, GoogleMapsEvent, GoogleMapsMarker, GoogleMapsMarkerOptions,
CameraPosition, GoogleMapsLatLng
} from "ionic-native";
import {Observable} from "rxjs/Rx";
private gMap: GoogleMap;
location: {lat: number, lng: number};
constructor(public navCtrl: NavController,
public platform:Platform
) {}
getMapresults() {
this.platform.ready().then(()=>{
console.log('Platform ready!');
this.gMap = new GoogleMap('mapid');
this.gMap.on(GoogleMapsEvent.MAP_READY)
.subscribe(()=>{
console.log('Map!');
});
}
Error:
Uncaught (in promise): [object Object]
package.json:
{
"name": "ionic-hello-world",
"author": "Ionic Framework",
"homepage": "http://ionicframework.com/",
"private": true,
"scripts": {
"ionic:build": "ionic-app-scripts build",
"ionic:serve": "ionic-app-scripts serve"
},
"dependencies": {
"#angular/common": "^2.1.1",
"#angular/compiler": "^2.1.1",
"#angular/compiler-cli": "2.1.1",
"#angular/core": "^2.1.1",
"#angular/forms": "2.1.1",
"#angular/http": "2.1.1",
"#angular/platform-browser": "^2.1.1",
"#angular/platform-browser-dynamic": "^2.1.1",
"#angular/platform-server": "^2.1.1",
"#ionic/storage": "1.1.6",
"angular2-google-maps": "^0.16.0",
"ionic-angular": "2.0.0-rc.3",
"ionic-native": "2.2.3",
"ionicons": "3.0.0",
"rxjs": "5.0.0-beta.12",
"zone.js": "0.6.26"
},
"devDependencies": {
"#ionic/app-scripts": "0.0.45",
"typescript": "2.0.6"
},
"cordovaPlugins": [
"cordova-plugin-whitelist",
"cordova-plugin-console",
"cordova-plugin-statusbar",
"cordova-plugin-device",
"cordova-plugin-splashscreen",
"ionic-plugin-keyboard"
],
"cordovaPlatforms": [
"ios",
{
"platform": "ios",
"version": "",
"locator": "ios"
}
],
"description": "firstMobApp: An Ionic project"
}
There are few problems in your code. You need to send some parameters to Google map API in order to load google maps.
import { Component } from '#angular/core';
import { NavController, Platform } from 'ionic-angular';
import { GoogleMap, GoogleMapsEvent, GoogleMapsLatLng } from 'ionic-native';
#Component({
selector: 'home-page',
templateUrl: 'home.html'
})
export class HomePage {
map: GoogleMap;
constructor(public navCtrl: NavController, public platform: Platform) {
platform.ready().then(() => {
this.loadMap();
});
}
loadMap(){
let location = new GoogleMapsLatLng(-34.9290,138.6010);
this.map = new GoogleMap('map', {
'backgroundColor': 'white',
'controls': {
'compass': true,
'myLocationButton': true,
'indoorPicker': true,
'zoom': true
},
'gestures': {
'scroll': true,
'tilt': true,
'rotate': true,
'zoom': true
},
'camera': {
'latLng': location,
'tilt': 30,
'zoom': 15,
'bearing': 50
}
});
this.map.on(GoogleMapsEvent.MAP_READY).subscribe(() => {
console.log('Map is ready!');
});
}
}
Related
I am going over the photo gallery ionic app tutorial. I am at the part in which I am able to take photos, store them and when the page is refreshed, reload them. The problem is that when refreshing the page, the photo is not loaded. The picture blinks and goes away.
Here is the basic code
photo.service.ts
import { Injectable } from '#angular/core';
import { Camera, CameraResultType, CameraSource, Photo} from '#capacitor/camera';
import { Filesystem, Directory } from '#capacitor/filesystem';
import { Storage } from '#capacitor/storage';
#Injectable({
providedIn: 'root'
})
export class PhotoService {
public photos: UserPhoto[] = [];
private PHOTO_STORAGE: string = 'photo';
constructor() { }
private async savePicture(photo: Photo){
const base64Data = await this.readAsBase64(photo);
const fileName = new Date().getTime() + '.jpeg';
const savedFile = await Filesystem.writeFile({
path: fileName,
data: base64Data,
directory: Directory.Data
});
return{
filepath: fileName,
webviewPath: photo.webPath
}
}
private async readAsBase64(photo: Photo){
const response = await fetch(photo.webPath!);
const blob = await response.blob();
return await this.convertBlobToBase64(blob) as string;
}
private convertBlobToBase64 = (blob: Blob) => new Promise((resolve, reject) => {
const reader = new FileReader;
reader.onerror = reject;
reader.onload = () => {
resolve(reader.result);
};
reader.readAsDataURL(blob);
});
public async addNewToGallery(){
const capturedPhoto = await Camera.getPhoto({
resultType: CameraResultType.Uri,
source: CameraSource.Camera,
quality: 100
});
const savedImageFile = await this.savePicture(capturedPhoto);
this.photos.unshift(savedImageFile);
Storage.set({
key: this.PHOTO_STORAGE,
value: JSON.stringify(this.photos),
});
}
public async loadSaved(){
const photoList = await Storage.get({key: this.PHOTO_STORAGE});
this.photos = JSON.parse(photoList.value) || [];
for(let photo of this.photos){
const readFile = await Filesystem.readFile({
path: photo.filepath,
directory: Directory.Data
});
photo.webviewPath = 'data:image/jpeg;base64, ${readFile.data}';
}
}
}
export interface UserPhoto {
filepath: string;
webviewPath: string;
}
tab2.page.ts:
import { Component } from '#angular/core';
import { PhotoService } from '../services/photo.service';
#Component({
selector: 'app-tab2',
templateUrl: 'tab2.page.html',
styleUrls: ['tab2.page.scss']
})
export class Tab2Page {
constructor(public photoService: PhotoService) { }
async ngOnInit(){
await this.photoService.loadSaved();
}
addPhotoToGallery(){
this.photoService.addNewToGallery();
}
}
tab2.page.html:
<ion-header [translucent]="true">
<ion-toolbar>
<ion-title>
Photo Gallery
</ion-title>
</ion-toolbar>
</ion-header>
<ion-content [fullscreen]="true">
<ion-fab vertical="bottom" horizontal="center" slot="fixed">
<ion-fab-button (click)="addPhotoToGallery()">
<ion-icon name="camera"></ion-icon>
</ion-fab-button>
</ion-fab>
<ion-grid>
<ion-row>
<ion-col size="6" *ngFor="let photo of photoService.photos; index as position">
<ion-img [src]="photo.webviewPath"></ion-img>
</ion-col>
</ion-row>
</ion-grid>
<app-explore-container name="Tab 2 page"></app-explore-container>
</ion-content>
package.json dump
{
"name": "photo-gallery",
"version": "0.0.1",
"author": "Ionic Framework",
"homepage": "https://ionicframework.com/",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"#angular/common": "~13.0.0",
"#angular/core": "~13.0.0",
"#angular/forms": "~13.0.0",
"#angular/platform-browser": "~13.0.0",
"#angular/platform-browser-dynamic": "~13.0.0",
"#angular/router": "~13.0.0",
"#capacitor/android": "3.4.0",
"#capacitor/app": "1.0.7",
"#capacitor/camera": "^1.2.3",
"#capacitor/core": "^3.3.4",
"#capacitor/filesystem": "^1.0.7",
"#capacitor/haptics": "1.1.3",
"#capacitor/ios": "3.4.0",
"#capacitor/keyboard": "1.2.0",
"#capacitor/status-bar": "1.0.6",
"#capacitor/storage": "^1.2.3",
"#ionic/angular": "^6.0.0",
"#ionic/pwa-elements": "^3.1.1",
"rxjs": "~6.6.0",
"tslib": "^2.2.0",
"zone.js": "~0.11.4"
},
"devDependencies": {
"#angular-devkit/build-angular": "~13.0.1",
"#angular-eslint/builder": "~13.0.1",
"#angular-eslint/eslint-plugin": "~13.0.1",
"#angular-eslint/eslint-plugin-template": "~13.0.1",
"#angular-eslint/template-parser": "~13.0.1",
"#angular/cli": "~13.0.1",
"#angular/compiler": "~13.0.0",
"#angular/compiler-cli": "~13.0.0",
"#angular/language-service": "~13.0.0",
"#capacitor/cli": "^3.3.4",
"#ionic/angular-toolkit": "^5.0.0",
"#types/jasmine": "~3.6.0",
"#types/jasminewd2": "~2.0.3",
"#types/node": "^12.11.1",
"#typescript-eslint/eslint-plugin": "5.3.0",
"#typescript-eslint/parser": "5.3.0",
"eslint": "^7.6.0",
"eslint-plugin-import": "2.22.1",
"eslint-plugin-jsdoc": "30.7.6",
"eslint-plugin-prefer-arrow": "1.2.2",
"jasmine-core": "~3.8.0",
"jasmine-spec-reporter": "~5.0.0",
"karma": "~6.3.2",
"karma-chrome-launcher": "~3.1.0",
"karma-coverage": "~2.0.3",
"karma-coverage-istanbul-reporter": "~3.0.2",
"karma-jasmine": "~4.0.0",
"karma-jasmine-html-reporter": "^1.5.0",
"protractor": "~7.0.0",
"ts-node": "~8.3.0",
"typescript": "~4.4.4"
},
"description": "An Ionic project"
}
I have an issues while try to add geolocation function in my app. I'm using https://ionicframework.com/docs/native/geolocation
In home.ts, call this findUserLocation() in ionViewDidLoad():
import { Geolocation } from '#ionic-native/geolocation/ngx';
...
constructor(private geolocation: Geolocation) {}
ionViewDidLoad(){
this.findUserLocation()
}
findUserLocation(){
let options = {
enableHighAccuracy: true,
timeout: 25000
};
this.geolocation.getCurrentPosition(options).then((position) => {
this.location = {
latitude: position.coords.latitude,
longitude: position.coords.longitude
};
this.mapsProvider.init(this.location, this.mapElement);
}).catch((error) => {
console.log('Error getting location', error);
});
}
And this is my package.json
"dependencies": {
"#angular/animations": "5.2.11",
"#angular/common": "5.2.11",
"#angular/compiler": "5.2.11",
"#angular/compiler-cli": "5.2.11",
"#angular/core": "5.2.11",
"#angular/forms": "5.2.11",
"#angular/platform-browser": "5.2.11",
"#angular/platform-browser-dynamic": "5.2.11",
"#ionic-native/core": "4.20.0",
"#ionic-native/geolocation": "^5.22.0",
"#ionic-native/splash-screen": "4.20.0",
"#ionic-native/status-bar": "4.20.0",
"#ionic/storage": "2.2.0",
"cordova-plugin-geolocation": "^4.0.2",
"ionic-angular": "3.9.9",
"ionicons": "3.0.0",
"rxjs": "^6.3.3",
"rxjs-compat": "^6.3.3",
"sw-toolbox": "3.6.0",
"zone.js": "0.8.29"
},
"devDependencies": {
"#ionic/app-scripts": "3.2.4",
"typescript": "2.6.2"
},
"description": "An Ionic project",
"cordova": {
"plugins": {
"cordova-plugin-geolocation": {}
}
}
And then when i run ionic serve, there's error in console:
ERROR TypeError: Object(...) is not a function
at Geolocation.getCurrentPosition (index.js:10)
at HomePage.webpackJsonp.263.HomePage.findUserLocation (home.ts:45)
at HomePage.webpackJsonp.263.HomePage.ionViewDidLoad (home.ts:34)
at ViewController._lifecycle (view-controller.js:487)
at ViewController._didLoad (view-controller.js:370)
at NavControllerBase._didLoad (nav-controller-base.js:789)
at t.invoke (polyfills.js:3)
at Object.onInvoke (core.js:4760)
at t.invoke (polyfills.js:3)
at r.run (polyfills.js:3)
Please help for the solution.
The Geolocation plugin is only available after the deviceready event has fired. You can find this here.
To solve your issue, you have to use Geolocation ONLY after Platform.ready() completes. Try to modify your code to something like this:
import { Geolocation } from '#ionic-native/geolocation/ngx';
import { Platform } from '#ionic/angular';
constructor(
private geolocation: Geolocation
public platform: Platform,
) {}
ionViewDidLoad(){
this.platform.ready().then(() => {
this.findUserLocation()
});
}
Also, make sure you have installed the plugin properly by running the following commands, then re-building/running your app:
ionic cordova plugin add cordova-plugin-geolocation
npm install #ionic-native/geolocation --save
I have following problem. My webpack is bundling files from node_modules. How can I prevent him from doing that? He is doing that, because i import files from node_modules in main.ts, but i have to do this. What am i doing wrong?
main.ts
import { NgModule } from '#angular/core';
import { platformBrowserDynamic } from '#angular/platform-browser-dynamic';
import { BrowserModule } from '#angular/platform-browser';
import { AppComponent } from './app/app.component';
#NgModule({
imports: [ BrowserModule ],
exports: [],
declarations: [AppComponent],
providers: [],
})
export class AppModule { }
platformBrowserDynamic().bootstrapModule(AppModule);
tsconfig.json
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": ["es2015", "dom"],
"noImplicitAny": true,
"suppressImplicitAnyIndexErrors": true
}
}
webpack.config.json
var webpack = require('webpack');
module.exports = {
entry : __dirname + '/src/main.ts',
output: {
path: __dirname + '/dist',
filename: 'app.bundle.js'
},
module: {
rules: [
{
test: /\.ts$/,
loader: 'ts-loader'
}
]
},
resolve: {
extensions: ['.js','.ts']
}
};
package.json
{
"name": "angular2",
"version": "1.0.0",
"scripts": {
"start": "webpack --progress"
},
"dependencies": {
"#angular/common": "~2.4.0",
"#angular/compiler": "~2.4.0",
"#angular/core": "~2.4.0",
"#angular/forms": "~2.4.0",
"#angular/http": "~2.4.0",
"#angular/platform-browser": "~2.4.0",
"#angular/platform-browser-dynamic": "~2.4.0",
"#angular/router": "~3.4.0",
"core-js": "^2.4.1",
"rxjs": "5.0.1",
"zone.js": "^0.7.4"
},
"devDependencies": {
"ts-loader": "^2.0.2",
"typescript": "^2.2.1",
"typings": "^2.1.0",
"webpack": "^2.3.0"
}
}
Test for .js files and exclude node modules in your loaders, example for using javascript(react) with babel-loader:
{
test: /.js?$/,
loader: 'babel-loader',
exclude: /node_modules/,
query: {
presets: [
'es2015', 'react', 'stage-0',
],
}
},
In your main.js file you can just do import Module from 'module' where 'module' is the name of your component. Webpack will bundle it if you refer to it like that.
Example if I want to include React: import React from 'react' - no relative paths needed.
I want focus to be set on my <ion-input> as I enter the page
This is my typescript code:
import { Component, Input, ViewChild,ElementRef,Renderer } from '#angular/core';
import { NavController, PopoverController, NavParams, ViewController, ModalController } from 'ionic-angular';
#Component({
selector: 'page-comments',
templateUrl: 'comments.html'
})
export class CommentsParentPage {
#ViewChild('input') myInput;
constructor(public navCtrl: NavController,private renderer: Renderer,
private elementRef: ElementRef, public modalCtrl: ModalController) {
}
ionViewLoaded() {
setTimeout(() => {
let element = this.elementRef.nativeElement.querySelector('input');
this.renderer.invokeElementMethod(element, 'focus', []);
},150);
}
}
And this is what i have done with my html file:
<ion-item>
<ion-input set-focuser type="text" placeholder="Write Your Comments" [(ngModel)]="addComment"></ion-input>
</ion-item>
Whenever I enter this page of my application, I would like the keyboard to be opened and focus to be set on ion-input
My config.xml includes:
<preference name="KeyboardDisplayRequiresUserAction" value="false" />
package.json
{
"name": "sample app",
"author": "",
"homepage": "http://ionicframework.com/",
"private": true,
"scripts": {
"clean": "ionic-app-scripts clean",
"build": "ionic-app-scripts build",
"ionic:build": "ionic-app-scripts build",
"ionic:serve": "ionic-app-scripts serve"
},
"dependencies": {
"#angular/common": "2.2.1",
"#angular/compiler": "2.2.1",
"#angular/compiler-cli": "2.2.1",
"#angular/core": "2.2.1",
"#angular/forms": "2.2.1",
"#angular/http": "2.2.1",
"#angular/platform-browser": "2.2.1",
"#angular/platform-browser-dynamic": "2.2.1",
"#angular/platform-server": "2.2.1",
"#ionic-native/core": "^3.4.4",
"#ionic-native/keyboard": "^3.4.4",
"#ionic/cloud-angular": "^0.10.0",
"#ionic/storage": "1.1.7",
"angular2-moment": "^1.1.0",
"google-libphonenumber": "^2.0.14",
"ionic-angular": "2.0.0-rc.4",
"ionic-gallery-modal": "0.0.7",
"ionic-native": "2.2.11",
"ionicons": "3.0.0",
"rxjs": "5.0.0-beta.12",
"zone.js": "0.6.26"
},
"devDependencies": {
"#ionic/app-scripts": "1.0.0",
"typescript": "2.0.9"
},
"cordovaPlugins": [
"ionic-plugin-keyboard",
"cordova-plugin-whitelist",
"cordova-plugin-console",
"cordova-plugin-statusbar",
"cordova-plugin-device",
"cordova-plugin-splashscreen",
"cordova-sqlite-storage",
"cordova-plugin-x-toast",
"cordova-plugin-camera",
"cordova-plugin-compat",
"cordova-plugin-image-picker",
"cordova.plugins.diagnostic",
{
"id": "phonegap-plugin-push",
"locator": "phonegap-plugin-push",
"variables": {
"SENDER_ID": "461076790064"
}
},
"cordova-plugin-contacts",
"ionic-plugin-deploy",
"cordova-plugin-x-socialsharing",
{
"locator": "https://github.com/napolitano/cordova-plugin-intent",
"id": "com.napolitano.cordova.plugin.intent"
},
"cordova-plugin-screen-orientation",
"cordova-plugin-file",
"cordova-plugin-file-transfer"
],
"cordovaPlatforms": [
{
"platform": "android",
"version": "",
"locator": "android"
}
],
"description": "ionic2: An Ionic project"
}
use ngAfterViewChecked:
See plnkr here
import { Component, Input, ViewChild,ElementRef,Renderer, AfterViewChecked,ChangeDetectorRef } from '#angular/core';
import { NavController, PopoverController, NavParams, ViewController, ModalController } from 'ionic-angular';
#Component({
selector: 'page-comments',
templateUrl: 'comments.html'
})
export class CommentsParentPage implements AfterViewChecked {
#ViewChild('input') myInput;
needsFocus: boolean;
constructor(public navCtrl: NavController,private renderer: Renderer,
private elementRef: ElementRef, public modalCtrl: ModalController,
private _changeDetectionRef: ChangeDetectorRef) {
}
ionViewDidEnter() {
this.needsFocus = true;
}
public ngAfterViewChecked(): void {
if (this.needsFocus) {
this.needsFocus = false;
this.myInput.setFocus();
this._changeDetectionRef.detectChanges();
}
}
You can do it using Directive as shown below.Hope code is self-explanatory.If you have any issue please comment below.
Play with Git Repo code.
You can View this on Ionic View: Id = F5F367AE
Note: Just tap My Page.
set-focuser.ts
import { Directive, Renderer, ElementRef } from '#angular/core';
import { Keyboard } from '#ionic-native/keyboard';
#Directive({
selector: '[set-focuser]' // Attribute selector
})
export class SetFocuser {
constructor(private renderer: Renderer, private elementRef: ElementRef, public keyboard: Keyboard) {
}
ngAfterViewInit() {
const element = this.elementRef.nativeElement.querySelector('input');
// to delay
setTimeout(() => {
this.renderer.invokeElementMethod(element, 'focus', []);
this.keyboard.show();
}, 500);
}
}
.html
<ion-input set-focuser type="text"></ion-input>
app.module.ts
import { SetFocuser } from "../components/set-focuser/set-focuser";
#NgModule({
declarations: [
SetFocuser,
],
Issues on your package.json
You have to remove "ionic-native": "2.2.11", module.
Use "#ionic/app-scripts": "1.1.4", instead of "#ionic/app-scripts": "1.0.0",
After the above changes run npm i
This is the official package.json file.
I know this is an old topic, but I faced a similar issue (in my case there was an error: 'setFocus is not a function'. My solution may help someone in the future (Ionic v5).
In this case I generated a component instead of a page, so I didn't have a module.ts file for the component. I had to add the component to the parent page's declarations.
declarations: [
MyModalComponent
]
Then in the component's typescript file, added the following lines and it worked as intended:
#ViewChild('myInputsReference', {static: false}) inputEl: IonInput;
ionViewDidEnter() {
this.setFocusOnInput();
}
setFocusOnInput() {
setTimeout(_ => { this.inputEl.setFocus()}, 200);
}
You can try simple method.
<div ng-init="getfocus()">
<ion-input id="myAnchor" type="text" placeholder="Write Your Comments"/>
</div>
In js file call a function with ng-init
function getfocus() {
document.getElementById("myAnchor").focus();
}
Hope this code will help you.if you get any error please comment.
Friends; I've tried to get new position of dragged marker but i failed. could you please help me. I can not get the dragged marker's new location.
addMarker(){
let marker = new google.maps.Marker({
map: this.map,
animation: google.maps.Animation.DROP,
position: this.map.getCenter(),
draggable: true
});
marker.addEventListener(plugin.google.maps.event.MARKER_DRAG_END, function(marker) {
marker.getPosition(function(latLng) {
marker.setTitle(latLng.toUrlValue());
marker.showInfoWindow();
});
});
}
I also tried this code but it fails too:
addMarker(){
let marker = new google.maps.Marker({
map: this.map,
animation: google.maps.Animation.DROP,
position: this.map.getCenter(),
draggable: true
});
marker.addEventListener(GoogleMapsEvent.MARKER_DRAG_END).subscribe(
data => {
marker.getPosition()
.then((LatLng) => {
alert('GoogleMapsEvent.MARKER_DRAG_END Lat ~ '+LatLng.lat() + ' And Long ~ '+LatLng.lng())
});
});
}
Packages that have installed:
"dependencies": {
"#angular/common": "2.2.1",
"#angular/compiler": "2.2.1",
"#angular/compiler-cli": "2.2.1",
"#angular/core": "2.2.1",
"#angular/forms": "2.2.1",
"#angular/http": "2.2.1",
"#angular/platform-browser": "2.2.1",
"#angular/platform-browser-dynamic": "2.2.1",
"#angular/platform-server": "2.2.1",
"#ionic/storage": "1.1.7",
"#types/google-maps": "^3.2.0",
"angular2-google-maps": "^0.17.0",
"ionic-angular": "2.0.0-rc.4",
"ionic-native": "2.2.16",
"ionicons": "3.0.0",
"promise": "^7.1.1",
"rxjs": "5.0.0-beta.12",
"zone.js": "0.6.26"
},
"devDependencies": {
"#ionic/app-scripts": "0.0.47",
"#types/google-maps": "3.2.0",
"typescript": "2.0.9"
},
Hello did you used ionic plugin add cordova-plugin-googlemaps plugin??
then try to add marker using following script
let element: HTMLElement = document.getElementById('map');
let map = new GoogleMap(element);
let ionic: GoogleMapsLatLng = new GoogleMapsLatLng(43.07,-89.38);
let markerOptions: GoogleMapsMarkerOptions = {
position: ionic,
title: 'Ionic',
draggable: true,
icon: 'assets/icon/cusom-marker.png'
};
map.addMarker(markerOptions)
.then((marker: GoogleMapsMarker) => {
marker.addEventListener(GoogleMapsEvent.MARKER_DRAG_START).subscribe(data =>{
})
marker.addEventListener(GoogleMapsEvent.MARKER_DRAG_END).subscribe(
data => {
marker.getPosition().then((LatLng) => {
alert(JSON.stringify(LatLng))
// alert('GoogleMapsEvent.MARKER_DRAG_END Lat ~ '+LatLng.lat() + ' And Long ~ '+LatLng.lng())
});
});
});
Hope its work for you...
try to use below code its work for me.
home.js
import { Component,ElementRef, ViewChild } from '#angular/core';
import { NavController, NavParams, ViewController,Platform } from 'ionic-angular';
import { GoogleMap, GoogleMapsEvent, GoogleMapsLatLng, CameraPosition, GoogleMapsMarkerOptions,GoogleMapsMarker } from 'ionic-native';
#Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
#ViewChild('map1') mapElement: ElementRef;
map1: any;
constructor(public navCtrl: NavController,public platform : Platform, public navParams: NavParams,public viewCtrl: ViewController) {
platform.ready().then(() => {
this.loadMap();
});
}
loadMap() {
// create a new map by passing HTMLElement
let element: HTMLElement = document.getElementById('map1');
let map1 = new GoogleMap(element);
// listen to MAP_READY event
map1.one(GoogleMapsEvent.MAP_READY).then(() => console.log('Map is ready!'));
map1.getMyLocation().then((location)=>{
// create LatLng object
let ionic: GoogleMapsLatLng = new GoogleMapsLatLng(location.latLng.lat,location.latLng.lng);
// create CameraPosition
let position: CameraPosition = {
target: ionic,
zoom: 18,
tilt: 30,
bearing: 140,
};
// move the map's camera to position
map1.moveCamera(position);
map1.setDebuggable( false )
let markerOptions: GoogleMapsMarkerOptions = {
position: ionic,
// title: 'Ionic',
draggable: true,
icon: './assets/icon/cusom-marker.png'
};
// add circle
map1.addCircle({
'center': ionic,
'radius': 60,
'strokeColor' : '#aec9f2',
'strokeWidth': 0,
'fillColor' : '#aec9f2' //becfea
});
map1.addMarker(markerOptions)
.then((marker: GoogleMapsMarker) => {
marker.addEventListener(GoogleMapsEvent.MARKER_DRAG_START).subscribe(data =>{
marker.setIcon({
'url': './assets/icon/move-marker.png',
'size': {
width: 50,
height: 50
}
});
})
marker.addEventListener(GoogleMapsEvent.MARKER_DRAG_END).subscribe(
data => {
marker.getPosition().then((LatLng) => {
// alert(JSON.stringify(LatLng))
marker.setIcon({
'url': './assets/icon/cusom-marker.png',
'size': {
width: 50,
height: 50
}
});
});
});
});
})
}
}
home.html
<ion-header>
<ion-navbar>
<ion-title>Home</ion-title>
</ion-navbar>
</ion-header>
<ion-content>
<div #map1 id="map1">
</div>
</ion-content>
compare your dependencies (package.json)
"dependencies": {
"#angular/common": "2.2.1",
"#angular/compiler": "2.2.1",
"#angular/compiler-cli": "2.2.1",
"#angular/core": "2.2.1",
"#angular/forms": "2.2.1",
"#angular/http": "2.2.1",
"#angular/platform-browser": "2.2.1",
"#angular/platform-browser-dynamic": "2.2.1",
"#angular/platform-server": "2.2.1",
"#ionic/storage": "1.1.7",
"ionic-angular": "2.0.0-rc.5",
"ionic-native": "2.2.11",
"ionicons": "3.0.0",
"rxjs": "5.0.0-beta.12",
"zone.js": "0.6.26",
"sw-toolbox": "3.4.0"
},
otherwise you can replace dependencies then go to root folder and type npm install.
i hope its work for you.