Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Use the multiplemarker.php class-- it contains geolocation and other …
…stuff. still needs editing
  • Loading branch information
jsn13002 committed Apr 13, 2017
1 parent 8049609 commit ae0cd70
Show file tree
Hide file tree
Showing 5 changed files with 217 additions and 0 deletions.
32 changes: 32 additions & 0 deletions geolocation.html
@@ -0,0 +1,32 @@
This function will be able to get the current location


<html>
<script src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script>
function getLocation(){
if (navigator.geolocation){
navigator.geolocation.getCurrentPostion(savePostion, postionError, {timeout:10000});
}
else{
//geolocation is not supported by the browser
}

}
function positionError(error){
var errorCode = error.code;
var message = error.message;
alert(message);

}

function savePosition(position){
$_post("geolocation.php", {lat: postion.coords.latitude, lng: position.coords.longitude});
}
</script>
<body>
<button onclick= "getLocation(); "> Current Location</button>
</body>
</html>


24 changes: 24 additions & 0 deletions geolocation.php
@@ -0,0 +1,24 @@
<?php
if (isset($_POST['lat'], $POST['lng'])){

$lat = $_POST['lat'];
$lng = $_POST['lng'];
$url = sprintf("https://maps.googleapis.com/maps/api/geocode/json?latlng=%s,%s", $lat, $lng);

$content = file_get_contents($url); //get the json content
$metadata= json_decode($content, true);

if(count($metadata['results']) > 0 ){
$result = $metadata['results'][0];
echo $result['formatted_address'];

}

else{
// no results
}
}



?>
106 changes: 106 additions & 0 deletions multiplemarkers.php
@@ -0,0 +1,106 @@


// first we will need to work on getting the current location using the google maps API

/// we can get the current location by using the functions form the geolocation.html


// now we use the geolocation to find the list of nearby locations

//https://developers.google.com/maps/documentation/javascript/store-locator?csw=1 is what we are using for reference

<html>
<body>
<script src = "http://maps.google.com/maps/api/js?sensor=false"></script>
<script src = "http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.10.1.min.js"> < /scipt>
<div id = "map" style = "width: 500pxl height: 400px; "> </div>
<script>
// this will allow us to get the geolocation for where the user is
function getLocation(){
if (navigator.geolocation){
navigator.geolocation.getCurrentPostion(savePostion, postionError, {timeout:10000});
}
else{
//geolocation is not supported by the browser
}
}
function positionError(error){
var errorCode = error.code;
var message = error.message;
alert(message);
}
function savePosition(position){
$_post("geolocation.php", {lat: postion.coords.latitude, lng: position.coords.longitude});
}
// once you get the geolocation: we proceed to getting a list of elements from my mysql database which we will use to find the array of location
</script>
var currentlocation = getLoaction(); // this is where the current location will be stored
<script>
// this is where we shall put the functions that will make our array for us
// we will need to connect the database to this.. which is am not sure of how to do...
select id, (3959* acos(cos(radians(37))))* cos(radians(lat)) * cos(radians(lng) - radians(-122)) + sin(radians(37))* sin(radians(lat)))) AS distance from currentlocation HAVING distance <25 ORDER BY distance LIMIT 0, 20; // this statement gets us the closest 20 locations within the radius fo 25 miles to the coordinate
</script>
<script type = "text/javascript">
// this will allow us to display a map with multiple markers
var locations = ['permit number', -33.890542, 151.274856]; // replace this with the array function that we will be using
var map = new google.maps.Map(document.getElementById('map')){
zoom: 10,
center: new google.maps.LatLng(-390.92, 151.25),s
mapTypeId: google.maps.mapTypeId.ROADMAP
});
var infowindow = new google.maps.InfoWindow();
var marker, i;
var markers = new Array();
for (i = 0; 0< locations.length; i++){
marker = new google.maps.Marker(
{
postion: new google.maps.LatLng(locations[i][1], locations[i][2]),
map: map
});
markers.push(marker);
google.maps.event.addEventListener(marker, 'click', (function(marker,i){
return function(){
infowindow.setContent(locations[i][0]);
infowindow.open(map,marker);
}
})(marker,i));
}
function autoCenter(){
var bounds = new google.maps.LatLngBounds();
$.each(marker, function(index, marker){
bounds.extend(marker.position);
});
map.fitBounds(bounds);
}
autoCenter();
</script>
</body>
</html>
8 changes: 8 additions & 0 deletions phpsqlsearch_dbinfo.php
@@ -0,0 +1,8 @@
// this will connect it to the mySQL database

<?php
$username= "username";
$password = "password" ;
$database= "username-databaseName";

?>
47 changes: 47 additions & 0 deletions storelocator.php
@@ -0,0 +1,47 @@
//provided by google for the geolocation api

<?php
require("phpsqlsearch_dbinfo.php");
// Get parameters from URL
$center_lat = $_GET["lat"];
$center_lng = $_GET["lng"];
$radius = $_GET["radius"];
// 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());
}
// Search the rows in the markers table
$query = sprintf("SELECT id, name, address, lat, lng, ( 3959 * acos( cos( radians('%s') ) * cos( radians( lat ) ) * cos( radians( lng ) - radians('%s') ) + sin( radians('%s') ) * sin( radians( lat ) ) ) ) AS distance FROM markers HAVING distance < '%s' ORDER BY distance LIMIT 0 , 20",
mysql_real_escape_string($center_lat),
mysql_real_escape_string($center_lng),
mysql_real_escape_string($center_lat),
mysql_real_escape_string($radius));
$result = mysql_query($query);
$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)){
$node = $dom->createElement("marker");
$newnode = $parnode->appendChild($node);
$newnode->setAttribute("id", $row['id']);
$newnode->setAttribute("name", $row['name']);
$newnode->setAttribute("address", $row['address']);
$newnode->setAttribute("lat", $row['lat']);
$newnode->setAttribute("lng", $row['lng']);
$newnode->setAttribute("distance", $row['distance']);
}
echo $dom->saveXML();
?>

0 comments on commit ae0cd70

Please sign in to comment.