DEV Community

GreggHume
GreggHume

Posted on

3 3

Google map loader api, how to include libraries like places

You want to include "drawing" | "geometry" | "localContext" | "places" | "visualization"?

Here you go:

import { Loader } from "@googlemaps/js-api-loader"

const loader = new Loader({
  apiKey: API_KEY,
  mapId: MAP_ID,
  version: "weekly",
  libraries: ["places"]
});
Enter fullscreen mode Exit fullscreen mode

If you were trying to access places on the google map instance it would have failed because it was not included. Now with adding the library it will work, here is some example code:

var service = new google.maps.places.PlacesService(map);

const request = {
  query: value,
  fields: ['name', 'geometry']
}

service.findPlaceFromQuery(request, function(results, status) {
  if (status === google.maps.places.PlacesServiceStatus.OK) {
    for (var i = 0; i < results.length; i++) {
      const place = results[i];
      if (!place.geometry || !place.geometry.location) return;

      new google.maps.Marker({
        map: map,
        position: place.geometry.location,
      });
    }
    map.setZoom(13);
    map.setCenter(results[0].geometry.location);
  }
});
Enter fullscreen mode Exit fullscreen mode

Image of Datadog

The Future of AI, LLMs, and Observability on Google Cloud

Datadog sat down with Google’s Director of AI to discuss the current and future states of AI, ML, and LLMs on Google Cloud. Discover 7 key insights for technical leaders, covering everything from upskilling teams to observability best practices

Learn More

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay