Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

vue google maps FAQ

José Miguel Gonçalves edited this pageAug 29, 2018 ·7 revisions

Frequently asked questions

I / Another package is already loading Google Maps! How do I use that instance of Google Maps instead?

To use a pre-loaded Google Maps API, passfalse to theload option:

Vue.use(VueGoogleMaps,{load:false})

When Google Maps has been loaded, run the following:

window.vueGoogleMapsInit(google)

Where is mygoogle?

Symptoms:

  • "ReferenceError: google is not defined"
  • How do I use Google Places service?
  • How do I use Google Directions service?

Why this happens: The Google Maps API library is loaded asynchronously byvue-google-maps.Hence it is not immediately available even when the page is loaded.Fortunately,vue-google-maps provides you a Promise that is resolved whengoogle is ready.

Solution:

this.$gmapApiPromiseLazy().then(()=>{varbounds=newgoogle.maps.LatLngBounds()/* etc */})

How do I talk to my map?

Symptoms:

  • You want to create a Map overlay, but don't know how to get reference to the map
  • You want to create a HeatMap, but don't know how to get reference to the map
  • You want tocreate markers manually for performance reasons, but don't know how to get a reference to the map

Solution: If you create your map like so:

<GmapMap ref="mymap" @click="doSomething()"></GmapMap>

Then you can refer to the map object:

methods:{doSomething(){this.$refs.mymap.$mapObject.panTo({lat:70,lng:0})// If you don't want to use the `zoom` property}}

$mapObject is not defined

Symptom: If you are trying to do something like this:

mounted(){this.$refs.mymap.$mapObject.panTo(ORIGIN)}

and get an error.

Why this happens: It's because it still takes time for the library still needs to wait forloaded, andthen it needs another cycle of the event loop before it can say,this.$mapObject = new google.maps.Map().

Therefore, do this:

mounted(){this.$refs.mymap.$mapPromise.then(()=>{this.$refs.mymap.$mapObject.panTo(ORIGIN)})}

Reference:https://github.com/xkjyeah/vue-google-maps/issues/294

TheInfoWindow is not opening when I click the marker!

Symptoms: You have something like this:<GmapMarker><GmapInfoWindow /></GmapMarker>, but clicking the marker does not open the info window!

Why this happens (TL;DR): whether anInfoWindow is open is controlled by itsopened prop. Therefore write:

<GmapMarker @click="infoWindowShown=true">  <GmapInfoWindow :opened="infoWindowShown" @closeclick="infoWindowShown = false"></GmapMarker>

Why so complicated? TheInfoWindow is a separate component fromMarker. ThereforeMarkershould not be modifying the internal state ofInfoWindow.To put this more concretely, you can close theInfoWindow by setting:opened="false", but theInfoWindow can also itself (if you click on the X). The only way to ensure that both parent and child can see a consistent state of the info window, is to define a variable likeinfoWindowShown in the parent.


[8]ページ先頭

©2009-2025 Movatter.jp