├── README ├── map-service.php ├── tutorial-part1.html └── tutorial-part2.html /README: -------------------------------------------------------------------------------- 1 | Code is under the MIT License 2 | Copyright 2009 Marc Grabanski 3 | 4 | 1) Edit tutorial-part1.html and tutorial-part2.html, replace my key=MYKEY with yours 5 | 2) Edit map-service.php, mysql credentials -------------------------------------------------------------------------------- /map-service.php: -------------------------------------------------------------------------------- 1 | $row['name'], 'lat' => $row['lat'], 'lng' => $row['lng'])); 11 | } 12 | echo json_encode(array("Locations" => $points)); 13 | exit; 14 | } 15 | 16 | // Save a point from our form 17 | if ($_POST['action'] == 'savepoint') { 18 | $name = $_POST['name']; 19 | if(preg_match('/[^\w\s]/i', $name)) { 20 | fail('Invalid name provided.'); 21 | } 22 | if(empty($name)) { 23 | fail('Please enter a name.'); 24 | } 25 | 26 | // Query 27 | $query = "INSERT INTO locations SET name='$_POST[name]', lat='$_POST[lat]', lng='$_POST[lng]', ip='$ip'"; 28 | $result = map_query($query); 29 | 30 | if ($result) { 31 | success(array('lat' => $_POST['lat'], 'lng' => $_POST['lng'], 'name' => $name)); 32 | } else { 33 | fail('Failed to add point.'); 34 | } 35 | exit; 36 | } 37 | 38 | function map_query($query) { 39 | // Connect 40 | mysql_connect('mysql_host', 'mysql_user', 'mysql_password') 41 | OR die(fail('Could not connect to database.')); 42 | 43 | mysql_select_db('mysql_database'); 44 | return mysql_query($query); 45 | } 46 | 47 | function fail($message) { 48 | die(json_encode(array('status' => 'fail', 'message' => $message))); 49 | } 50 | 51 | function success($data) { 52 | die(json_encode(array('status' => 'success', 'data' => $data))); 53 | } 54 | ?> -------------------------------------------------------------------------------- /tutorial-part1.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Google Maps and jQuery 5 | 6 | 7 | 8 | 12 | 13 | 64 | 71 | 72 | 73 |
74 | 75 | 78 | 79 | -------------------------------------------------------------------------------- /tutorial-part2.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | PHP, jQuery and Google Maps 4 | 5 | 9 | 22 | 123 | 124 | 125 |
126 | 127 |
128 | Add a Point to the Map 129 | 130 |
131 | 132 | 133 |
134 |
135 | 136 | 137 |
138 | 139 |
140 |
141 |
142 | 143 |
144 | 145 | --------------------------------------------------------------------------------