iOS移动设备上Leaflet标记不显示问题求助
Hey Vincent, let's dig into why your Leaflet markers aren't showing up on iOS 11.3.1. Here are targeted troubleshooting steps and fixes to try out:
iOS 11.3.1 is an older mobile system, and newer Leaflet versions might have dropped support for its outdated Safari engine. Try downgrading to Leaflet 1.7.1—this version is known to play nicer with legacy iOS Safari. Replace your existing Leaflet resource links with these CDN versions:
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.7.1/dist/leaflet.css" /> <script src="https://unpkg.com/leaflet@1.7.1/dist/leaflet.js"></script>
Older iOS Safari can have issues loading relative-path resources or handling cross-origin icon files. Leaflet uses built-in marker icons by default, but you can explicitly set the icon path to a reliable CDN to avoid loading failures. Add this line before initializing your markers:
L.Icon.Default.imagePath = 'https://unpkg.com/leaflet@1.7.1/dist/images/';
Your zp_openstreetmap.css might contain styles that break marker rendering on old iOS. Temporarily remove this CSS link from your test page—if markers start showing up, you’ll know the problem lies in that file. You can then debug it line by line to find conflicting rules (look for properties like transform, position, or overflow that might affect marker elements).
Connect your iOS device to a Mac, open Safari on the Mac, and enable the Developer menu. From there, you can inspect your test page, check the console for errors (like 404s for marker icons or JS syntax issues), and see exactly what’s failing. This is often the fastest way to pinpoint the root cause.
Strip down your page to the absolute basics (no jQuery, no extra plugins) to isolate the issue. Use this simplified code to see if markers work:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1"> <link rel="stylesheet" href="https://unpkg.com/leaflet@1.7.1/dist/leaflet.css" /> <script src="https://unpkg.com/leaflet@1.7.1/dist/leaflet.js"></script> <title>Test Leaflet Marker</title> </head> <body> <div id="osm_map" style="width:100%; height:600px;"></div> <script> var map = L.map('osm_map').setView([57.325, -6.275], 10); L.tileLayer('https://{s}.tile.opentopomap.org/{z}/{x}/{y}.png').addTo(map); L.Icon.Default.imagePath = 'https://unpkg.com/leaflet@1.7.1/dist/images/'; L.marker([57.150,-6.100]).addTo(map); L.marker([57.500,-6.450]).addTo(map); </script> </body> </html>
If markers appear here, the problem is likely with the leaflet-providers.js plugin or your custom CSS.
内容的提问来源于stack exchange,提问作者vincent3569

