In the era of mobile internet, map services have become an essential tool for users to access geographic information. Whether for locating places, planning routes, or exploring surroundings, maps offer great convenience. AMap API provides a rich set of interfaces that, combined with PHP's powerful backend capabilities, make it easy to build feature-rich interactive maps.
First, register an AMap developer account, create a new web service application, and obtain your developer key, which is required to call the API.
Below is the basic HTML structure and code for implementing interactive map markers:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Interactive Map Marker Example</title> <style> #map { width: 100%; height: 600px; } </style> </head> <body> <div id="map"></div> <script src="https://webapi.amap.com/maps?v=1.4.15&key=YOUR_KEY"></script> <script src="https://webapi.amap.com/ui/1.1/main.js"></script> <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <script> // Create map instance var map = new AMap.Map("map", { zoom: 13, // Set map zoom level center: [116.397428, 39.90923] // Set map center coordinates }); // Add map toolbar control AMap.plugin(['AMap.ToolBar'], function() { map.addControl(new AMap.ToolBar()); }); // Map click event map.on('click', function(e) { // Get latitude and longitude of clicked point var lnglat = e.lnglat; var longitude = lnglat.getLng(); var latitude = lnglat.getLat(); // Create marker and add to map var marker = new AMap.Marker({ position: [longitude, latitude] }); map.add(marker); // Show info window with coordinates var infoWindow = new AMap.InfoWindow({ content: 'Longitude: ' + longitude + '<br>Latitude: ' + latitude }); marker.on('click', function() { infoWindow.open(map, marker.getPosition()); }); }); </script> </body> </html>
This article demonstrates how to combine PHP with AMap API to implement a basic interactive map marker feature. Developers can build upon this foundation to add advanced functions such as route planning and location searching. Map technologies greatly enhance user experience by offering convenient geographic information display and interaction.