javascript - Using Leaflet map in php page - Stack Overflow

I was searching for free maps as an alternative to google maps to use in my website. As I searched I fo

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>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744791366a4593935.html

相关推荐

  • javascript - Using Leaflet map in php page - Stack Overflow

    I was searching for free maps as an alternative to google maps to use in my website. As I searched I fo

    15小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信