Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
MAP
  • Loading branch information
Arif Prabawa authored and Arif Prabawa committed Apr 22, 2017
1 parent 6c874ea commit 881258b
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 14 deletions.
68 changes: 56 additions & 12 deletions Wello/www/map.php
Expand Up @@ -97,20 +97,64 @@

<script>

function initMap() {
var myLatLng = {lat: -25.363, lng: 131.044};

function initMap() {
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 4,
center: myLatLng
});

var marker = new google.maps.Marker({
position: myLatLng,
map: map,
title: 'Hello World!'
center: new google.maps.LatLng(41.79947, -72.37209),
zoom: 12
});
var infoWindow = new google.maps.InfoWindow;

// Change this depending on the name of your PHP or XML file
downloadUrl('http://wellreportapp.uconn.edu/xmlGenerate.php', function(data) {
var xml = data.responseXML;
var markers = xml.documentElement.getElementsByTagName('marker');
Array.prototype.forEach.call(markers, function(markerElem) {
var id = markerElem.getAttribute('id');
var name = markerElem.getAttribute('name');
var address = markerElem.getAttribute('streetName');
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 marker = new google.maps.Marker({
map: map,
position: point
});
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=AIzaSyCNSoPsxLd0LbvQaH9R6npO7jj-jKAXyQ4&callback=initMap">
Expand All @@ -124,4 +168,4 @@ notes :
we will need a file where we import the well name, address, longiture and latitude within the range we chose
we need a food loop for it
-->
-->
49 changes: 49 additions & 0 deletions Wello/www/xmlGenerate.php
@@ -0,0 +1,49 @@
<?php

require("cred.php");

// Start XML file, create parent node

$dom = new DOMDocument("1.0");
$node = $dom->createElement("markers");
$parnode = $dom->appendChild($node);

// Opens a connection to a MySQL server

$connection=mysql_connect ('localhost', $username, $password);
if (!$connection) { die('Not connected : ' . mysql_error());}

// Set the active MySQL database

$db_selected = mysql_select_db($database, $connection);
if (!$db_selected) {
die ('Can\'t use db : ' . mysql_error());
}

// Select all the rows in the markers table

$query = "SELECT * FROM well_completion_report WHERE 1 LIMIT 10";
$result = mysql_query($query);
if (!$result) {
die('Invalid query: ' . mysql_error());
}

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

// Iterate through the rows, adding XML nodes for each

while ($row = @mysql_fetch_assoc($result)){
// Add to XML document node
$node = $dom->createElement("marker");
$newnode = $parnode->appendChild($node);
$newnode->setAttribute("id",$row['Permit_Number']);
$newnode->setAttribute("streetNumber", $row['Well_Street_Number']);
$newnode->setAttribute("streetName", $row['Well_Street_Name']);
$newnode->setAttribute("Town", $row['Well_Town']);
$newnode->setAttribute("lat", $row['Well_Latitude']);
$newnode->setAttribute("lng", $row['Well_Longitude']);
}

echo $dom->saveXML();

?>
4 changes: 2 additions & 2 deletions map.php
Expand Up @@ -117,10 +117,10 @@
title: 'Hello World!'
});
}
</script>
</script>
<script async defer
src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCNSoPsxLd0LbvQaH9R6npO7jj-jKAXyQ4&callback=initMap">
</script>
</script>
</body>


Expand Down

0 comments on commit 881258b

Please sign in to comment.