最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Using Leaflet map in php page - Stack Overflow

programmeradmin1浏览0评论

I was searching for free maps as an alternative to google maps to use in my website. As I searched I found leaflet. Referring the tutorial I tried creating a simple map in my localhost. But its loading blank. I am using leaflet for the first time. Is there anything I am missing out in my code? Can anyone help me..? Thanks in advance.

Here is my code:

<html>
<head>
   <meta charset="utf-8">
   <link rel="stylesheet" href=".7.3/leaflet.css" />
   <script src=".7.3/leaflet.js"></script>
   <style>
       #map{ height: 100% }
   </style>
</head>
<body>
    <div id="map"></div>
    <script>
        var map = L.map('map',{
            center: [43.64701, -79.39425],
            zoom: 15
        });
    </script>
</body>
</html>

I was searching for free maps as an alternative to google maps to use in my website. As I searched I found leaflet. Referring the tutorial I tried creating a simple map in my localhost. But its loading blank. I am using leaflet for the first time. Is there anything I am missing out in my code? Can anyone help me..? Thanks in advance.

Here is my code:

<html>
<head>
   <meta charset="utf-8">
   <link rel="stylesheet" href="http://cdn.leafletjs./leaflet-0.7.3/leaflet.css" />
   <script src="http://cdn.leafletjs./leaflet-0.7.3/leaflet.js"></script>
   <style>
       #map{ height: 100% }
   </style>
</head>
<body>
    <div id="map"></div>
    <script>
        var map = L.map('map',{
            center: [43.64701, -79.39425],
            zoom: 15
        });
    </script>
</body>
</html>
Share Improve this question edited Feb 6, 2019 at 9:24 kboul 14.6k5 gold badges47 silver badges58 bronze badges asked Sep 5, 2018 at 12:58 AishwaryasAishwaryas 6433 gold badges19 silver badges45 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 4

You need to add a tile layer to your map and try using one of the latest leaflet versions, such as 1.3.3. Moreover set a height like this:

#map{ height: 500px }

Try this

var map = L.map('map').setView([43.64701, -79.39425], 15);

L.tileLayer('https://{s}.tile.openstreetmap/{z}/{x}/{y}.png', {
  attribution: '&copy; <a href="https://www.openstreetmap/copyright">OpenStreetMap</a> contributors'
}).addTo(map);

L.marker([51.5, -0.09]).addTo(map)
  .bindPopup('A pretty CSS3 popup.<br> Easily customizable.')
  .openPopup();
#map {
  height: 500px
}
<link rel="stylesheet" type="text/css" href="https://unpkg./[email protected]/dist/leaflet.css">

<script src='https://unpkg./[email protected]/dist/leaflet.js
'></script>
<div id="map"></div>

发布评论

评论列表(0)

  1. 暂无评论