Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Access to full google.maps object #209

Closed
cviccaro opened this issue Mar 10, 2016 · 8 comments
Closed

Access to full google.maps object #209

cviccaro opened this issue Mar 10, 2016 · 8 comments

Comments

@cviccaro
Copy link

Hi, loving your work so far, but am curious, will this library ever grant access to the full google.maps object, similar to angular1's implementation of google-maps? (see here: http://angular-ui.github.io/angular-google-maps/#!/api/GoogleMapApi)

Getting the google.maps object lets you create, for example...

A1 code to create new DirectionsRenderer and DirectionsService:

            uiGmapGoogleMapApi.then(function(maps) {
                vm.gmaps = maps;
                vm.map.directionsDisplay = new vm.gmaps.DirectionsRenderer();
                vm.map.directionsService = new vm.gmaps.DirectionsService();
            });

Or to create a new LatLng object:

var latlng = new vm.gmaps.LatLng(lat, lng);

Is this going to be possible with this library?

EDIT: I do see that the google object is available globally.. so we can do var latlng = new google.maps.LatLng(lat,lng); However, isn't it one goals of the project to prevent the google object from polluting the global namespace?

EDIT to EDIT: Also see now we can use LatLngLiteral interface, so that deals with one problem:

import {LatLngLiteral} from 'angular2-google-maps/core';

...

var latlng = <LatLngLiteral>{lat: this.latitude, lng: this.longitude};
this.map.setCenter(latlng);
@parmod-arora
Copy link
Contributor

Hi cviccaro,

Please refer below mentioned comment to get access of google.maps object.

#139 (comment)

@cviccaro
Copy link
Author

@parmod-arora,

Thanks. I've managed to get the map object, but I was referring to the whole SDK's API. The DirectionsRenderer and DirectionsService are not located on the map object itself, but on the google.maps namespace.

In rethinking this, however, I imagine direct access to the full google.maps namespace won't be available by design, but instead wrappers around each will be available later down the line.

@parmod-arora
Copy link
Contributor

@cviccaro,

Correct me if I am wrong, You want to access google.maps and want to play with DirectionsRenderer and DirectionsService services.

Below is the code.

declare var google: any;

@Directive({
  selector: 'my-comp',  // <home></home>
})
export class MyComp {
  constructor(private _mapsWrapper:GoogleMapsAPIWrapper){
    _mapsWrapper.getMap().then((m: mapTypes.GoogleMap) => {
      console.log(google.maps);
    });
  }
}

@cviccaro
Copy link
Author

@parmod-arora Exactly. As I wrote in my edit to the original post, I see that the global google object is indeed available, so my question has deviated a bit I guess. Will this project eventually remove the google object from the global namespace, providing a module to import to initialize a DirectionsRenderer or DirectionsService?

@sebholstein
Copy link
Owner

Will this project eventually remove the google object from the global namespace

No, this is not a goal for the project. It shoud provide an easy to use abstraction layer for angular2/google maps. We can think about how we use certain services of the google maps API like DirectionsRenderer or DirectionsService. I let this open to discuss how a good API for Angular 2 could look like

@cthrax
Copy link

cthrax commented Mar 23, 2016

If I'm understanding everything here correctly, wouldn't the most angular way of handling this be to have a service that returns the global object? This would enable mocking for testing and avoid global dependencies.

@RedFour
Copy link

RedFour commented Oct 1, 2016

Hi @cviccaro you mentioned you got the google.maps object working, could you show me how you did that? Was it via the GoogleMapsAPIWrapper?

@stale
Copy link

stale bot commented Nov 14, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Nov 14, 2018
@stale stale bot closed this as completed Nov 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants