-
I want to use Example code from Google Maps developer site: function initMap() {
var directionsService = new google.maps.DirectionsService();
var directionsRenderer = new google.maps.DirectionsRenderer();
var chicago = new google.maps.LatLng(41.850033, -87.6500523);
var mapOptions = {
zoom:7,
center: chicago
}
var map = new google.maps.Map(document.getElementById('map'), mapOptions);
directionsRenderer.setMap(map);
}
function calcRoute() {
var start = document.getElementById('start').value;
var end = document.getElementById('end').value;
var request = {
origin: start,
destination: end,
travelMode: 'DRIVING'
};
directionsService.route(request, function(result, status) {
if (status == 'OK') {
directionsRenderer.setDirections(result);
}
});
} I'm using Vue 3. Here is just enough of a component to show what I am currently trying. <template>
<GMapMap ref="map" ... />
</template>
<script>
setup() {
const map = ref(null)
onMounted(() => console.log(map.value))
return { map }
}
</script> The value is |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Finally figured it out. Even though watch(
() => map.value,
async (val) => {
const mapValue = val
const interval = setInterval(async () => {
if (val.$mapObject) {
clearInterval(interval)
await setRoutes()
}
}, 500)
}
) |
Beta Was this translation helpful? Give feedback.
-
Hi @34fame You solution with timeout may work in your case, but will fail depending on internet speed or your users. |
Beta Was this translation helpful? Give feedback.
Hi @34fame
To access google.maps and other objects from google follow this example:
https://vue-map.netlify.app/examples/how-to-access-google-maps-object.html
You solution with timeout may work in your case, but will fail depending on internet speed or your users.