Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $servername = "localhost";
- $username = "";
- $password = "";
- $dbname = "myparkspace";
- $conn = mysqli_connect($servername, $username, $password, $dbname);
- if (!$conn) {
- die("Connection failed: " . mysqli_connect_error());
- }
- $sql = 0;
- $sql = "SELECT * FROM geolocations";
- $result = $conn->query($sql);
- if ($result->num_rows > 0) {
- while($row = $result->fetch_assoc()) {
- $id = $row['id'];
- $name = $row['name'];
- $address = $row['address'];
- $municipality = $row['municipality'];
- $city = $row['city'];
- $lat = $row['lat'];
- $lng = $row['lng'];
- $icon_type = $row['icon_type'];
- }
- } else {
- echo "ERROR";
- }
- ?>
- <script>
- function initMap()
- {
- <?php echo "var center = {lat: $lat, lng: $lng}"; ?>;
- var locations = [
- ['<b><?php echo $name; ?> </b><br>\ Grad: <?php echo $city; ?> <br> Opshtina: <?php echo $municipality; ?> <br> Cena: /<br>\ <a href="https://goo.gl/maps/p3DSib4umW32">Get Directions</a>',
- 42.0065365,21.4225759, 'parking_garage'],
- ['<b>Testovski parking </b><br>\ Grad: Skopje <br> Opshtina: Test <br> Cena: /<br>\ <a href="https://goo.gl/maps/p3DSib4umW32">Get Directions</a>',
- 41.9972736,21.42957, 'parking'],
- ];
- var map = new google.maps.Map(document.getElementById('map'),
- {
- zoom: 9,
- center: center
- });
- var iconBase = 'https://maps.google.com/mapfiles/ms/icons/';
- var icons = {
- parking:
- {
- icon: iconBase + 'green-dot.png'
- },
- parking_garage:
- {
- icon: iconBase + 'yellow-dot.png'
- }
- };
- var infowindow = new google.maps.InfoWindow({});
- var marker, count;
- for (count = 0; count < locations.length; count++)
- {
- marker = new google.maps.Marker(
- {
- position: new google.maps.LatLng(locations[count][1], locations[count][2]),
- map: map,
- title: locations[count][0],
- icon: icons[locations[count][3]].icon, //<- iconBase position
- });
- google.maps.event.addListener(marker, 'click', (function (marker, count)
- {
- return function ()
- {
- infowindow.setContent(locations[count][0]);
- infowindow.open(map, marker);
- }
- })(marker, count));
- }
- }
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement