How to use MySQL and JavaScript to implement a simple map marking function
The map marking function is very common in modern web applications. It can be used to mark specific locations, Display location information or display geographic data, etc. In this article, we'll cover how to write a simple map marker function using a MySQL database and JavaScript, and provide specific code examples.
1. Preparation
Before we start, we need to prepare some basic environments and tools:
2. Create database and table
First, we need to create a table in the MySQL database to store the location information of map markers. We can use the following SQL statement to create a table named "markers":
CREATE TABLE `markers` ( `id` INT(11) NOT NULL AUTO_INCREMENT, `name` VARCHAR(50) NOT NULL, `lat` FLOAT(10,6) NOT NULL, `lng` FLOAT(10,6) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
This table contains four fields: id, name, lat and lng. The id field is an auto-incremented primary key, the name field is used to store the name of the tag, and the lat and lng fields are used to store the latitude and longitude of the tag respectively.
3. Write the front-end code
Next, we can write the front-end HTML and JavaScript code to implement the map marking function.
<div id="map"></div> <button onclick="addMarker()">添加标记</button>