Membuat Script Store Location Google Map di Web PHP7 & Mysql

Google Store Location adalah layanan pointing lokasi tempat bisnis yang seringkali digunakan oleh Developer aplikasi untuk menyematkan po...


Google Store Location adalah layanan pointing lokasi tempat bisnis yang seringkali digunakan oleh Developer aplikasi untuk menyematkan posisi letak tempat bisnis ke dalam google map. Aplikasi map ini dapat menampilkan fitur nearby location atau find location store.

Saya akan berbagi tutorial basic programer menggunakan PHP 7 dan MySQL untuk menampilkan data lokasi bisnis yang sudah tersimpan kedalam database. Sebelum mengikuti tutorial berikut ada baiknya anda mendaftarkan diri terlebih dahulu untuk mendapatkan google map API Key.

Langkah pertama yang perlu dilakukan adalah :


  • Buatlah file ke dalam sebuah folder utama config.php

1
2
3
4
5
<?php
$username="root";
$password="";
$database="test";
?>


  • Berikutnya buatlah fungsi XML untuk menampilkan databse lokasi map dengan nama file map.php

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
require("config.php");

function parseToXML($htmlStr)
{
$xmlStr=str_replace('<','&lt;',$htmlStr);
$xmlStr=str_replace('>','&gt;',$xmlStr);
$xmlStr=str_replace('"','&quot;',$xmlStr);
$xmlStr=str_replace("'",'&#39;',$xmlStr);
$xmlStr=str_replace("&",'&amp;',$xmlStr);
return $xmlStr;
}

// 1. Create a database connection

$connection = mysqli_connect('localhost', $username, $password, $database);
if (!$connection) {
    die("Database connection failed: " . mysqli_connect_error());
}


$result = mysqli_query($connection,"SELECT * FROM markers");
if (!$result) {
  die('Invalid query: ' . mysql_error());
}

header("Content-type: text/xml");

// Start XML file, echo parent node
echo '<markers>';

// Iterate through the rows, printing XML nodes for each
while ($row = mysqli_fetch_assoc($result)){
  // Add to XML document node
  echo '<marker ';
  echo 'name="' . parseToXML($row['name']) . '" ';
  echo 'address="' . parseToXML($row['address']) . '" ';
  echo 'lat="' . $row['lat'] . '" ';
  echo 'lng="' . $row['lng'] . '" ';
  echo 'type="' . $row['type'] . '" ';
  echo '/>';
}

// End XML file
echo '</markers>';

?>


  • Setelah proses diatas selesai dikerjakan, buatlah database store location dengan script dibawah

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
-- phpMyAdmin SQL Dump
-- version 4.8.0
-- https://www.phpmyadmin.net/
--
-- Host: 127.0.0.1
-- Generation Time: May 06, 2018 at 08:46 AM
-- Server version: 10.1.31-MariaDB
-- PHP Version: 7.2.4

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET AUTOCOMMIT = 0;
START TRANSACTION;
SET time_zone = "+00:00";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;

--
-- Database: `test`
--

-- --------------------------------------------------------

--
-- Table structure for table `markers`
--

CREATE TABLE `markers` (
  `id` int(11) NOT NULL,
  `name` varchar(60) NOT NULL,
  `address` varchar(80) NOT NULL,
  `lat` float(10,6) NOT NULL,
  `lng` float(10,6) NOT NULL,
  `type` varchar(30) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

--
-- Dumping data for table `markers`
--

INSERT INTO `markers` (`id`, `name`, `address`, `lat`, `lng`, `type`) VALUES
(1, 'Cakrudi.com 1', 'Jl. Al Wasliyah,, RT.3/RW.4, Jati, Pulo Gadung, Kota Jakarta Timur,', -6.192359, 106.895950, 'bar'),
(2, 'Cakrudi.com 2', 'Jl. Jenderal Ahmad Yani Kav. 49, Rawasari, Cempaka Putih', -6.193842, 106.890160, 'bar'),
(3, 'Cakrudi.com 3', 'Jalan Perintis Kemerdekaan Kav. 99, Pulogadung, RT.1/RW.1, RT.1/RW.1', -6.185831, 106.889084, 'bar');

--
-- Indexes for dumped tables
--

--
-- Indexes for table `markers`
--
ALTER TABLE `markers`
  ADD PRIMARY KEY (`id`);

--
-- AUTO_INCREMENT for dumped tables
--

--
-- AUTO_INCREMENT for table `markers`
--
ALTER TABLE `markers`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=10;
COMMIT;

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;


  • Langkah terakhir adalah memanggil isi database dengan javascript yang sudah terinclude KEY API map dengan membuat file index.thml seperti dibawah ini.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
<!DOCTYPE html >
<html>
  <head>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
    <title>Using MySQL and PHP with Google Maps</title>
    <style>
      /* Always set the map height explicitly to define the size of the div
       * element that contains the map. */
      #map {
        height: 100%;
      }
      /* Optional: Makes the sample page fill the window. */
      html, body {
        height: 100%;
        margin: 0;
        padding: 0;
      }
    </style>
  </head>

  <body>
    <div id="map"></div>

    <script>
      var customLabel = {
        restaurant: {
          label: 'R'
        },
        bar: {
          label: 'B'
        }
      };

        function initMap() {
        var map = new google.maps.Map(document.getElementById('map'), {
          center: new google.maps.LatLng(-6.2192359, 106.895950),
          zoom: 14
        });
        var infoWindow = new google.maps.InfoWindow;

          // Change this depending on the name of your PHP or XML file
          downloadUrl('http://localhost/map/map.php', function(data) {
            var xml = data.responseXML;
            var markers = xml.documentElement.getElementsByTagName('marker');
            Array.prototype.forEach.call(markers, function(markerElem) {
              var name = markerElem.getAttribute('name');
              var address = markerElem.getAttribute('address');
              var type = markerElem.getAttribute('type');
              var point = new google.maps.LatLng(
                  parseFloat(markerElem.getAttribute('lat')),
                  parseFloat(markerElem.getAttribute('lng')));

              var infowincontent = document.createElement('div');
              var strong = document.createElement('strong');
              strong.textContent = name
              infowincontent.appendChild(strong);
              infowincontent.appendChild(document.createElement('br'));

              var text = document.createElement('text');
              text.textContent = address
              infowincontent.appendChild(text);
              var icon = customLabel[type] || {};
              var marker = new google.maps.Marker({
                map: map,
                position: point,
                label: icon.label
              });
              marker.addListener('click', function() {
                infoWindow.setContent(infowincontent);
                infoWindow.open(map, marker);
              });
            });
          });
        }



      function downloadUrl(url, callback) {
        var request = window.ActiveXObject ?
            new ActiveXObject('Microsoft.XMLHTTP') :
            new XMLHttpRequest;

        request.onreadystatechange = function() {
          if (request.readyState == 4) {
            request.onreadystatechange = doNothing;
            callback(request, request.status);
          }
        };

        request.open('GET', url, true);
        request.send(null);
      }

      function doNothing() {}
      
      
    </script>
    <script async defer
    src="https://maps.googleapis.com/maps/api/js?key=PASANG_KEY_KAMU&callback=initMap">
    </script>
  </body>
</html>

Terimakasih sudah berkunjung di cakrudi.com

COMMENTS

BLOGGER: 1

Nama

2019,1,2020,1,Action Figure,1,Adventure,2,agro,1,android,4,API,1,aplikasi digital,5,artikel,28,artis,2,automotif,2,berita,27,bisnis,4,Cara,2,Cerita,2,Cerito Loro,1,chord,1,css3,1,desain,1,Diorama,1,download,1,download windows 11,1,ekonomi,3,facebook,1,Featured,2,Figur Karakter,1,fintech,1,game,1,ganti casing pc,1,Gaza,1,gerhana bulan,1,google map,1,gunung,1,gym,1,happy asmara,2,hardware,1,Hasil Bumi,1,headline,5,hiburan,1,hoax,1,html,2,html5,1,install ulang windows,1,ios,4,ios developer,1,iphone,1,javascript,2,jawa tengah,1,jawa timur,2,jual koi blitar,1,k-pop,1,kacamata tembus pandang,1,kartu prakerja gelombang 12,1,keamanan siber,1,kehamilan,1,kejadian misteri,1,kesehatan,4,kisah mistis,2,kisah wali songo,1,koi blitar,1,koi nias blitar,1,kompilasi happy asmara,1,komputer,2,Kopi,1,kuliner,3,lagu,1,lagu jawa,2,link download windows 11,1,lirik lagu,1,macbook,1,Mainan,1,marketplace,1,middleware,1,milenial,2,misteri,4,mistis,4,Music,2,musik,5,Musisi,1,mysql,1,Natal,1,nativescript,2,Node.js,1,nusantara,10,olahraga,3,online,1,osx,1,otomotif,2,Palestina,1,pantai,1,pantai banteng mati,1,peluncuran windows 11,1,pemrograman,2,pendakian,1,pengertian SEO,3,Perjalanan,1,perubahan iklim,1,photography,3,php,1,Piala Dunia 2018,1,pilkada 2018,3,Pink Floyd,1,playlist lagu jawa,1,Potensi Usaha,1,prakerja gelombang 12,1,prakerja2021,1,preview windows 11,1,Produk,1,programer,1,properti,1,rakit komputer,1,realme,1,religi,4,review,4,rilis windows 11,1,rumah,2,Satru happy asmara,1,sejarah,5,sejarah gamelan,1,Selebritis,1,Seniman,1,SEO,4,smartphone,1,spesifikasi windows 11,1,stadion,1,sunan ampel,1,Tak Ikhlasno,1,teknologi,12,tips,2,toyota,1,tradisi jawa,3,traveler,2,trip,2,tsunami,1,tutorial,21,tutorial ganti casing pc,1,tutorial html,1,tutorial ios,1,Tutorial SEO,3,Ulasan,1,Unggulan,1,UUITE,1,video,2,Video Klip,4,Wes Tatas,1,windows 11,1,windows 11 developer,1,wisata,7,Yerusalem,1,yoga,1,youtuber,2,
ltr
item
Tutorial Komputer Dan Blog Nusantara: Membuat Script Store Location Google Map di Web PHP7 & Mysql
Membuat Script Store Location Google Map di Web PHP7 & Mysql
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg2tpbRjd9bOrAu9fSqw3zIhrMyuGz4vwVLJOJfkrJZ7H9zBCKP7Bqt03f2rnzazGLXGH9nB_gncA28AF3Ntl-I-2YQ6tvTU8u3v62RqMnprNRMLbueiTPKmiQBcB30FyVrNe0GVunBqEg/s320/membuat_script_store_location_google_map.jpg
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg2tpbRjd9bOrAu9fSqw3zIhrMyuGz4vwVLJOJfkrJZ7H9zBCKP7Bqt03f2rnzazGLXGH9nB_gncA28AF3Ntl-I-2YQ6tvTU8u3v62RqMnprNRMLbueiTPKmiQBcB30FyVrNe0GVunBqEg/s72-c/membuat_script_store_location_google_map.jpg
Tutorial Komputer Dan Blog Nusantara
https://cakrudicom.blogspot.com/2018/05/membuat-script-store-location-google.html
https://cakrudicom.blogspot.com/
https://cakrudicom.blogspot.com/
https://cakrudicom.blogspot.com/2018/05/membuat-script-store-location-google.html
true
1076625099600691775
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS PREMIUM CONTENT IS LOCKED STEP 1: Share to a social network STEP 2: Click the link on your social network Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy Table of Content