question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

feat(GoogleMap): Expose map for use with other apis

See original GitHub issue

Feature Description

I have a map loaded on my screen, but I also want to use the Places Api. Although geocoding is supported by the library, places is not.

The map, and map instance, are created solely through my template

        <google-map [options]="options" class="col-sm-8">
            <map-marker
                [options]="markerOptions"
                [position]="markerPosition"
            ></map-marker>
        </google-map>

I have been trying the following code

        const map1: any = document.querySelector("google-map") as unknown;
        console.log("lookup", map1)

        const map2: GoogleMap = map1;
        var request = {
            query: 'albina',
            fields: ['name', 'geometry'],
        };
        var service = new google.maps.places.PlacesService(map2);
        service.findPlaceFromQuery(request, (results, status) => console.log(results, status))

This works in javascript - the querySelector returns the dom node, but it can be passed successfully to PlacesService. As I am using typescript I keep being told that I can’t pass an html element (not withstanding my attempts to override the type).

Really what I want is to access the map as is, rather than using dom lookups, but I cannot work out how to access that. As you can see, I am able to create and pass options to the component, but don’t know angular well enough to get the map back

Use Case

I also want to use the Places Api which requires me to pass a google map. the obvious candidate is the one created by this component, but I cannot see how to access it

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
crisbetocommented, Jun 5, 2022

Something like this:

import {ViewChild} from '@angular/core';
import {GoogleMap} from '@angular/google-maps';

@Component()
class YourComponent {
  @ViewChild(GoogleMap) map: GoogleMap;

  ngAfterViewInit() {
    console.log(this.map);
  }
}
0reactions
angular-automatic-lock-bot[bot]commented, Jul 16, 2022

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Overview | Maps JavaScript API - Google Developers
The Maps JavaScript API features four basic map types (roadmap, satellite, hybrid, and terrain) which you can modify using layers and styles, controls...
Read more >
Use the Google Maps API to build a custom map with markers
In this video we'll be building a custom styled Google map with multiple custom markers, using the Google Maps JavaScript API.
Read more >
Google Maps JavaScript API Tutorial - YouTube
In this video I will work a little bit with the Google Maps API as requested by some of my subscribers. We will...
Read more >
Removing the Google Maps API Premier Terms-of-Use/Logo ...
If you use the Google Maps service in any way, they request that you retain their branding. It is infact in the Terms...
Read more >
Use Google Maps built into your car when offline
You can use offline maps for reliable navigation and safety features when your car has a poor internet connection. Offline maps can be...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found