Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php require_once('connection.php'); ?>
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <!-- Required meta tags -->
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
- <!-- Bootstrap CSS -->
- <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" integrity="sha384-9gVQ4dYFwwWSjIDZnLEWnxCjeSWFphJiwGPXr1jddIhOegiu1FwO5qRGvFXOdJZ4" crossorigin="anonymous">
- <title>Google maps</title>
- <style>
- #map {
- height: 400px;
- width: 100%;
- }
- </style>
- </head>
- <body>
- <h1>Google maps</h1>
- <div id="map"></div>
- <div class="container-fluid">
- <div class="row">
- <div class="col-sm-4">
- <h1>Manuaalne lisamine</h1>
- <input type="hidden" id="point_change_id" value="0">
- <div class="form-group">
- <label for="pointAddName">Name</label>
- <input type="text" class="form-control" id="pointAddName" placeholder="Name">
- </div>
- <div class="form-group">
- <label for="pointAddLatitude">Latitude</label>
- <input type="text" class="form-control" id="pointAddLatitude" placeholder="Latitude">
- </div>
- <div class="form-group">
- <label for="pointAddLongitude">Longitude</label>
- <input type="text" class="form-control" id="pointAddLongitude" placeholder="Longitude">
- </div>
- <button type="button" class="btn btn-primary" id="pointAddBtn">Submit</button>
- <div class="jquery-message"></div>
- <hr>
- </div>
- <div class="col-md-8">
- <table class="table table-hover table-bordered">
- <thead>
- <tr>
- <th>Name</th>
- <th>Lat, lng</th>
- <th></th>
- </tr>
- </thead>
- <tbody id="markers_table"></tbody>
- </table>
- </div>
- </div>
- </div>
- <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
- <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js" integrity="sha384-cs/chFZiN24E4KMATLdqdvsezGxaGsi4hLGOzlXwp5UZB1LY//20VyM2taTB4QvJ" crossorigin="anonymous"></script>
- <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js" integrity="sha384-uefMccjFJAIv6A+rW+L4AHf99KvxDjWSu1z9VI8SKNVmz4sk7buKt/6v9KI65qnm" crossorigin="anonymous"></script>
- <script>
- function initMap() {
- var uluru = {lat: -25.363, lng: 131.044};
- var map = new google.maps.Map(document.getElementById('map'), {
- zoom: 4,
- center: uluru
- });
- $.getJSON("get_markers.php", function(data) {
- if(data.status == 1){
- for(i = 0; i < data.markers.length; i++){
- const curMarker = data.markers[i];
- var marker = new google.maps.Marker({
- position: {lat: parseFloat(curMarker.latitude),
- lng: parseFloat(curMarker.longitude)},
- map: map
- });
- $("#markers_table").append('<tr>' +
- '<td>' + curMarker.name + '</td>' +
- '<td>' + parseFloat(curMarker.latitude) + ', ' + parseFloat(curMarker.longitude) + '</td>' +
- '<td>' +
- '<button type="button" class="btn btn-info" id="editBtn" data-point-id="'+ curMarker.ID +'">Edit</button>' +
- '<button type="button" class="btn btn-danger" id="deleteBtn" data-point-id="'+ curMarker.ID +'">Delete</button>' +
- '</td>' +
- '</tr>');
- }
- }else{
- $(".jquery-message").html('<div class="alert alert-warning">' + data.message + '</div>');
- }
- });
- /*marker.addListener('click', function(){
- map.setCenter(marker.getPosition());
- });*/
- google.maps.event.addListener(map, 'click', function(event) {
- $("#pointAddLatitude").val(event.latLng.lat);
- $("#pointAddLongitude").val(event.latLng.lng);
- });
- }
- $("#pointAddBtn").on("click", function(){
- const name = $("#pointAddName").val(),
- lat = $("#pointAddLatitude").val(),
- lng = $("#pointAddLongitude").val();
- $.post('jquery/insert-new-point.php', {name: name, lat: lat, lng: lng})
- .done(function(data){
- const json = JSON.parse(data);
- let alertClass = 'info';
- if(json.status == 0){
- alertClass = 'warning';
- }
- $(".jquery-message").html('<div class="alert alert-' + alertClass + '">' + json.message + '</div>');
- });
- });
- </script>
- <script async defer src="https://maps.googleapis.com/maps/api/js?key=AIzaSyA_BIjwknbV0ROM9uprm3dO4v3Lkju9JCw&callback=initMap">
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement