English 中文(简体)
在SvelteKit拥有一系列坐标的Load基本谷歌地图
原标题:Load basic Google Map with array of coordinates in SvelteKit
最佳回答

“enterography

Repo with fixes:


Your code has three problems:

1. Missing ./index.js

Diagnosed by:read wrong in local services console afterloading page.

Fix: 删去<script> tag from RUS.

2. Referencing document outside browser context.

Diagnosed by:,read wrong in local services console afterloading page (with #1)。 或检查青.树脂中的错误。

onMount(。 (Alternatively use SvelteKit browser )

3. #map element has 0px height.

Diagnosed by: Inspectioning elements in browser dev instruments.

Fix: 调整中央支助事务。 (标准固定装置是使用px,更好的固定装置是确保母体具有非零高度。)


UPDATE: I updated the project with (SvelteKit) best practices:

  • Use @googlemaps/js-api-loader.
  • Use bind instead of id
  • Use element style props
  • Use 100% height
  • Don t commit sensitive data like API keys

每项改动都用于个人承诺:https://github.com/Leftium/kit-demos/commits/google-maps/

最后的法典就是这样:

<script lang="ts">
    import  ../app.css ;
    import { onMount } from  svelte ;
    import { Loader } from  @googlemaps/js-api-loader ;

    import { PUBLIC_GOOGLEMAPS_API_KEY } from  $env/static/public ;

    // Bindings
    let mapElement: HTMLElement;

    onMount(async function () {
        const loader = new Loader({
            apiKey: PUBLIC_GOOGLEMAPS_API_KEY,
            version:  weekly 
        });

        const { Map } = await loader.importLibrary( maps );

        let map = new Map(mapElement, {
            center: { lat: -34.397, lng: 150.644 },
            zoom: 8
        });
    });
</script>

<div bind:this={mapElement} style:height={ 100% } style:width={ 100% } />
问题回答

暂无回答




相关问题
How to decide the current point reach on google map?

How to decide the current point reach on google map? I have a list of points (pickup points) of a route that I want to show in my google map with polyline. Now i have to get the current location of ...

Topographical or relief data in Map APIs

I was wondering if anyone knew of any map APIs that offer topographical or relief data? I ve had a quick look at Google and Bing APIs, but could find nothing there. Google allow you to view a map as ...

Using maps on Windows Mobile

I m experimenting with maps on different mobile platforms. Getting Google Maps to work on Android was easy, following this tutorial. Getting the same to work on Windows Mobile is a different matter. ...

Adding a custom icon to a google map

I need a hand adding a custom icon to some Google Maps javascript. Code below for your reference: function populateMap() { var map = new GMap2(document.getElementById("map")); map.setCenter(new ...

RSS to KML Overlay

I m want to display my blog as a Google Map overlay (each post contains geotags). How can I dynamically create a KML overlay from an RSS? Or better, how can I create a loop (PHP) that would display ...

开放街道地图管理员

我需要开放Street的标记管理员。 地图,如山角地图。

热门标签