4

I'm using Angular Google Maps (latest @agm/core) but can't get panTo or setCenter to work it simply does nothing.

I import GoogleMapsAPIWrapper like this:

import { GoogleMapsAPIWrapper } from '@agm/core';

I then inject it into my constructor:

constructor(
injector: Injector,
private _wrapper: GoogleMapsAPIWrapper
){
super(injector);
}

Then I try to call the above method in a function like so:

resetMap():void
{
  this._wrapper.setCenter({lat:53.097900,
  lng:-1.661963});
  this._wrapper.panTo({lat:53.097900,
  lng:-1.661963});
}

I have also tried referencing the map as a ViewChild of type AgmMap but there is no public property to setCenter or panTo, as below;

@ViewChild('agmMap') agmMap:AgmMap;

Is there a way I can reference the google map control directly instead of the angular wrapper?

Please can anyone advise what I'm doing wrong? or how I am meant to reference the map to call methods against it.

David Hawkins
  • 1,049
  • 1
  • 10
  • 30
  • 1
    I'm having similar frustrations with this library. Any luck on this? I see it's been some time. – Christopher Marshall Jun 01 '17 at 18:19
  • 1
    Everything can be done by changing the various properties on the `@ViewChild`, and settings `usePanning` to true, but I'd much rather use the actual panTo method. Your way of using a child components seems too convoluted – f.khantsis Jun 09 '17 at 04:50

0 Answers0