PHP - Procedural Maps
I am making a space game. The game requires a map. The map needs to contain one or more galaxies. Each galaxy should have from 100 to 1000 star systems. Each star system needs to possess a random number of planets from 1-10.
I suspect that I can use while loops to control the number of galaxies star systems and planets, but I need to know how to assign coordinates when making the universe. Similar TutorialsThis topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=321234.0 Hi all, I work on a php project. I wrote it in procedural way. As project grows, it stating be harder to maintain obviously and I want to convert project ( or at lease key features) to oo code. My intention is to replace part which for example connects to database and then use the rest of the script and then move to another part write it in oo and replace old part. I wrote a simple class called Connection, just to handle connection. When I make object it connects, I retrieve some info from database using query as class function. However, there is no way I can execute my procedural login script after I made a connection object. And question is why? Do I need to write whole Database class to handle it? Can I merge oo and procedural php code together in once script? Code sample: Code: [Select] class Connection{ // database access paramiters var $host = 'localhost'; var $data_base = 'database'; var $user = 'user'; var $pass = 'pass'; var $con_handle; // constructing object with automatic connetction to db function __construct(){ $this->connect(); } function connect(){ // open a connection to the database server $this->con_handle = new mysqli ($this->host, $this->user, $this->pass); if (mysqli_connect_errno()) { echo("Could not open connection to database server"); exit; } // selecting database $this->con_handle->select_db($this->data_base) or die(mysql_error()); } } Code: [Select] //{ few includes here} $connection= new Connection(); //{rest of my login script} I am just wanting to know what the other forms of this type of conditonal would be, the type of if statement is as follows: if ($_POST) {print_r($_POST);} Just seen it a few times now, I know this means if $_POST exists. use the print_r() function to display the entire post array suber global variable. But what are the other combinations other than just if true? Like how are they used like this, like if I wanted to see if a random variable is not identical to another etc. Any helps appreciated, Jez. Folks,
Look what I found he My procedural style code is this alongside their OOP:
<?php if (!$conn) { $error = mysqli_connect_error(); $errno = mysqli_connect_errno(); print "$errno: $error\n"; exit(); } // Get the total number of records from our table "students". $total_pages = $conn->query('SELECT * FROM browsing_histories')->num_rows; //I NEED HELP TO SUBSTITUTE THIS TO PROCEDURAL STYLE // Check if the page number is specified and check if it's a number, if not return the default page number which is 1. $page = isset($_GET['page']) && is_numeric($_GET['page']) ? $_GET['page'] : 1; // Number of results to show on each page. $num_results_on_page = 5; // if ($stmt = $conn->prepare('SELECT * FROM following_histories ORDER BY id LIMIT ?,?')) { if($query = "SELECT id,date_and_time,query_type,followed_word,query_string,browsed_page_original,browsed_page_converted,referral_page_original,referral_page_converted,username,gender,age_range,date_of_birth,skin_complexion,height,weight,sexual_orientation,religion,education,profession,marital_status,working_status,country_of_birth,home_town,home_neighbourhood,home_borough,home_council,home_city,home_county,home_district,home_region,home_state,home_country FROM browsing_histories WHERE username = ? ORDER BY id LIMIT ? OFFSET ?"){ //my substitution of above line $stmt = mysqli_prepare($conn,$query); //MY SUBSTITUTION OF ABOVE LINE // Calculate the page to get the results we need from our table. $calc_page = ($page - 1) * $num_results_on_page; //$stmt->bind_param('ii', $calc_page, $num_results_on_page); mysqli_stmt_bind_param($stmt,'sii',$followee_username,$calc_page,$num_results_on_page); //MY SUBSTITUTION OF ABOVE LINE //$stmt->execute(); mysqli_stmt_execute($stmt); //MY SUBSTITUTION OF ABOVE LINE // Get the results... //$result = $stmt->get_result(); $result = mysqli_stmt_get_result($stmt) //MY SUBSTITUTION OF ABOVE LINE ?> <!DOCTYPE html> <html> <head> <title>PHP & MySQL Pagination by CodeShack</title> <meta charset="utf-8"> <style> html { font-family: Tahoma, Geneva, sans-serif; padding: 20px; background-color: #F8F9F9; } table { border-collapse: collapse; width: 500px; } td, th { padding: 10px; } th { background-color: #54585d; color: #ffffff; font-weight: bold; font-size: 13px; border: 1px solid #54585d; } td { color: #636363; border: 1px solid #dddfe1; } tr { background-color: #f9fafb; } tr:nth-child(odd) { background-color: #ffffff; } .pagination { list-style-type: none; padding: 10px 0; display: inline-flex; justify-content: space-between; box-sizing: border-box; } .pagination li { box-sizing: border-box; padding-right: 10px; } .pagination li a { box-sizing: border-box; background-color: #e2e6e6; padding: 8px; text-decoration: none; font-size: 12px; font-weight: bold; color: #616872; border-radius: 4px; } .pagination li a:hover { background-color: #d4dada; } .pagination .next a, .pagination .prev a { text-transform: uppercase; font-size: 12px; } .pagination .currentpage a { background-color: #518acb; color: #fff; } .pagination .currentpage a:hover { background-color: #518acb; } </style> </head> <body> <table> <tr> <th>Name</th> <th>Age</th> <th>Join Date</th> </tr> <?php while ($row = $result->fetch_assoc()): ?> <tr> <td><?php echo $row['id']; ?></td> <td><?php echo $row['followee_username']; ?></td> <td><?php echo $row['follower_username']; ?></td> </tr> <?php endwhile; ?> </table> <?php if (ceil($total_pages / $num_results_on_page) > 0): ?> <ul class="pagination"> <?php if ($page > 1): ?> <li class="prev"><a href="pagination.php?page=<?php echo $page-1 ?>">Prev</a></li> <?php endif; ?> <?php if ($page > 3): ?> <li class="start"><a href="pagination.php?page=1">1</a></li> <li class="dots">...</li> <?php endif; ?> <?php if ($page-2 > 0): ?><li class="page"><a href="pagination.php?page=<?php echo $page-2 ?>"><?php echo $page-2 ?></a></li><?php endif; ?> <?php if ($page-1 > 0): ?><li class="page"><a href="pagination.php?page=<?php echo $page-1 ?>"><?php echo $page-1 ?></a></li><?php endif; ?> <li class="currentpage"><a href="pagination.php?page=<?php echo $page ?>"><?php echo $page ?></a></li> <?php if ($page+1 < ceil($total_pages / $num_results_on_page)+1): ?><li class="page"><a href="pagination.php?page=<?php echo $page+1 ?>"><?php echo $page+1 ?></a></li><?php endif; ?> <?php if ($page+2 < ceil($total_pages / $num_results_on_page)+1): ?><li class="page"><a href="pagination.php?page=<?php echo $page+2 ?>"><?php echo $page+2 ?></a></li><?php endif; ?> <?php if ($page < ceil($total_pages / $num_results_on_page)-2): ?> <li class="dots">...</li> <li class="end"><a href="pagination.php?page=<?php echo ceil($total_pages / $num_results_on_page) ?>"><?php echo ceil($total_pages / $num_results_on_page) ?></a></li> <?php endif; ?> <?php if ($page < ceil($total_pages / $num_results_on_page)): ?> <li class="next"><a href="pagination.php?page=<?php echo $page+1 ?>">Next</a></li> <?php endif; ?> </ul> <?php endif; ?> </body> </html> <?php //$stmt->close(); mysqli_stmt_close($stmt); //MY SUBSTITUTION OF ABOVE LINE } ?> Edited February 2, 2019 by phpsane Hi All, I have the following code which works fine: $mysqli = new mysqli("server", "user", "pass", "database"); if($mysqli->connect_error) { exit('Could not connect'); } $sql = "SELECT customer_contactname, customer_companyname, customer_phonenumber, customer_emailaddress, customer_address1, customer_address2, customer_city, customer_postcode FROM ssm_customer WHERE customer_id = ?"; $stmt = $mysqli->prepare($sql); $stmt->bind_param("s", $_GET['q']); $stmt->execute(); $stmt->store_result(); $stmt->bind_result($ccontname, $ccompname, $cphoneno, $cemail, $cad1, $cad2, $ccity, $cpost); $stmt->fetch(); $stmt->close(); however, when i use my dbconn.php as an include rather than the top section of this code, i get the following error: function prepare() on null The error references the following $stmt = $mysqli->prepare($sql); In my database connection file, i am using the following: $conn = mysqli_connect($db_servername, $db_username, $db_password, $db_name); This seems to be the issue and i believe i am mixing procedural and object based but not sure why there should be a difference here? when i used my database connection file, i do change $mysqli->prepare to $conn->prepare Kind Regards Edited February 4, 2019 by Adamhumbugcreate table mimi (mimiId int(11) not null, mimiBody varchar(255) ); <?php //connecting to database include_once ('conn.php'); $sql ="SELECT mimiId, mimiBody FROM mimi"; $result = mysqli_query($conn, $sql ); $mimi = mysqli_fetch_assoc($result); $mimiId ='<span>No: '.$mimi['mimiId'].'</span>'; $mimiBody ='<p class="leading text-justify">'.$mimi['mimiBody'].'</p>'; ?> //what is next? i want to download pdf or text document after clicking button or link how to do that hi all.. i am so beginner in php,,i use php with mysql.. i want to do the map for branches of supermarket ,,so when i put the mouse in city it the city turn red then when i click the city another page open with the name of my branches of the supermarket whit the street of each of the branches is... i am wondering if i should use photoshop for the map to color each city with red so that if i have 8 branches in the country i will need 8 maps addtional to the orginal one??? and what`s the code 4 my q?? and i need tips in what each code does.. sorry 4 bothering u all >>>it `s just one of my dream is to be good at php ,, i am sick of hoping that i am at it i want to be good at it not just hoping I'm having trouble loading this kind of KML with PHP http://code.google.com/apis/maps/documentation/mapsdata/developers_guide_protocol.html#RetrievingFeatures example <atom:entry xmlns='http://www.opengis.net/kml/2.2' xmlns:atom='http://www.w3.org/2005/Atom' xmlns:batch='http://schemas.google.com/gdata/batch' xmlns:gd='http://schemas.google.com/g/2005'> <atom:id> http://maps.google.com/maps/feeds/features/userID/mapID/full/featureID</atom:id> <atom:published>2008-08-14T17:46:06.462Z</atom:published> <atom:updated>2008-08-14T18:12:31.589Z</atom:updated> <atom:category scheme='http://schemas.google.com/g/2005#kind' ..... it seems like the column in atom:entry, etc is causing this. $response = simplexml_load_string($response); print_r($response); the above just gives an empty SimpleXMLElement Object() Any ideas Hi guys Mods please move if this is the wrong place to ask. I have a google maps api added to my web site but i want to be able to position "pins" on the map to show all the the registered clubs in an area... eg the user searches dublin and all teh clubs pop up... My question is.. is there anyway to do this without needing the user to supply the long/lat.. ie can it be gotten automatically?? I really just want it to work off the addrees/area they supplied when they registered. thanks tt Hi all I am trying to get the lat and long properties from the googlemaps geocoding api. $xml=simplexml_load_file($url); if ($xml === false) { echo "Failed loading XML\n"; foreach(libxml_get_errors() as $error) { echo "\t", $error->message; } } else{ $path = $xml->xpath( "/GeocodeResponse/result/geometry/location"); $lat = $path->lat; $lng = $path->lng; echo $lat; echo $lng; $sql1 = "UPDATE tbl_clubs set lat='$lat',lng='$lng' where club_id =$id"; echo $sql1; $result1 = mysqli_query($dbConn,$sql1) or die($mysqli_error($dbConn)); } This is the XML I am using <GeocodeResponse> <status>OK</status> <result> <type>establishment</type> <type>point_of_interest</type> <type>stadium</type> <formatted_address>Aldridge Rd, Perry Barr, Birmingham B42 2ET, UK</formatted_address> <address_component> </address_component> <address_component> </address_component> <address_component> </address_component> <address_component> <long_name>West Midlands</long_name> <short_name>West Midlands</short_name> <type>administrative_area_level_2</type> <type>political</type> </address_component> <address_component> <long_name>England</long_name> <short_name>England</short_name> <type>administrative_area_level_1</type> <type>political</type> </address_component> <address_component> <long_name>United Kingdom</long_name> <short_name>GB</short_name> <type>country</type> <type>political</type> </address_component> <address_component> <long_name>B42 2ET</long_name> <short_name>B42 2ET</short_name> <type>postal_code</type> </address_component> <geometry> <location> <lat>52.5196698</lat> <lng>-1.8986236</lng> </location> <location_type>GEOMETRIC_CENTER</location_type> <viewport> <southwest> <lat>52.5183208</lat> <lng>-1.8999726</lng> </southwest> <northeast> <lat>52.5210188</lat> <lng>-1.8972746</lng> </northeast> </viewport> </geometry>
But I am getting the following response Notice: Trying to get property of non-object in /home/sites/1a/9/95f15f28a6/public_html/results/getLatLng.php on line 22 I am guessing my path is wrong, any guidance would be great i have code that i found and modified slightly that pulls data from mysql and plots it on a google map. this works fine as is. what i want to do is change the pin colour depending on a value from mysql. the java is outside of the while loop and i can not get it to work from inside the loop. this line of code changes the pin colour var icon = new google.maps.MarkerImage("http://maps.google.com/mapfiles/ms/micons/red.png", im crap with javascript and sorry if this is better in java forum. any help greatly appreciated Code: [Select] $dbcnx = mysql_connect ("$dbserver", "$dbuser", "$dbpass"); mysql_select_db("$dbname") or die(mysql_error()); ?> <html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"/> <title>Google Map API V3 with markers</title> <style type="text/css"> body { font: normal 10pt Helvetica, Arial; } #map { width: 700px; height: 600px; border: 0px; padding: 0px; } </style> <script src="http://maps.google.com/maps/api/js?v=3&sensor=false" type="text/javascript"></script> <script type="text/javascript"> //Sample code written by August Li var icon = new google.maps.MarkerImage("http://maps.google.com/mapfiles/ms/micons/red.png", new google.maps.Size(32, 32), new google.maps.Point(0, 0), new google.maps.Point(16, 32)); var center = null; var map = null; var currentPopup; var bounds = new google.maps.LatLngBounds(); function addMarker(lat, lng, info) { var pt = new google.maps.LatLng(lat, lng); bounds.extend(pt); var marker = new google.maps.Marker({ position: pt, icon: icon, map: map }); var popup = new google.maps.InfoWindow({ content: info, maxWidth: 300 }); google.maps.event.addListener(marker, "click", function() { if (currentPopup != null) { currentPopup.close(); currentPopup = null; } popup.open(map, marker); currentPopup = popup; }); google.maps.event.addListener(popup, "closeclick", function() { map.panTo(center); currentPopup = null; }); } function initMap() { map = new google.maps.Map(document.getElementById("map"), { center: new google.maps.LatLng(0, 0), zoom: 14, mapTypeId: google.maps.MapTypeId.ROADMAP, mapTypeControl: false, mapTypeControlOptions: { style: google.maps.MapTypeControlStyle.HORIZONTAL_BAR }, navigationControl: true, navigationControlOptions: { style: google.maps.NavigationControlStyle.SMALL } }); <?php $query = mysql_query("SELECT * FROM poi_example"); while ($row = mysql_fetch_array($query)){ $name=$row['name']; $lat=$row['lat']; $lon=$row['lon']; $desc=$row['desc']; echo ("addMarker($lat, $lon,'<b>$name</b><br/>$name');\n"); } ?> center = bounds.getCenter(); map.fitBounds(bounds); } </script> </head> <body onload="initMap()" style="margin:0px; border:0px; padding:0px;"> <div id="map"></div> </html> I am attempting to create a Map on my web page that will have the directions (which will be dynamically pulled from a database) however I have been unable to find a good tutorial on how to achieve this, also there doesn't seem to be any PHP classes available out there (for free anyway) to create this easily. Any suggestions? Hi All, I have code to generate a route in google maps on my site. The code works great in Firefox but not in IE8. It works in IE8 if you just have just a start and finish only but whe you add a waypoint in the route does not show. Any ideas? Code: [Select] <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true"> </script> <script type="text/javascript"> var directionDisplay; var geocoder; var directionsService = new google.maps.DirectionsService(); var latlng = new google.maps.LatLng(54.559322587438636, -4.1748046875); function load() { geocoder = new google.maps.Geocoder(); directionsDisplay = new google.maps.DirectionsRenderer(); var myOptions = { zoom: 6, mapTypeId: google.maps.MapTypeId.ROADMAP, center: latlng, mapTypeControl: true, mapTypeControlOptions: { style: google.maps.MapTypeControlStyle.HORIZONTAL_BAR, position: google.maps.ControlPosition.TOP_RIGHT }, navigationControl: true, navigationControlOptions: { style: google.maps.NavigationControlStyle.ZOOM_PAN, position: google.maps.ControlPosition.TOP_LEFT} }; var map = new google.maps.Map(document.getElementById('map'), myOptions); directionsDisplay.setMap(map); var directionRendererOptions ={ suppressMarkers: true, polylineOptions:{ strokeColor: "#FF0000", strokeOpacity: 1, strokeWeight: 3 } }; directionsDisplay.setOptions(directionRendererOptions); var start = '<?php echo $start; ?>'; var end = '<?php echo $end; ?>'; <?php if($via != null){ echo "var points = ["; foreach($via as $point){ if($point != ""){ echo "{location:"; echo " '".$point."'"; echo "},"; } } echo "];\n"; } ?> var request = { origin:start, waypoints: points, destination:end, travelMode: google.maps.DirectionsTravelMode.DRIVING }; directionsService.route(request, function(response, status) { if (status == google.maps.DirectionsStatus.OK) { directionsDisplay.setDirections(response); } }); geocoder.geocode( { 'address': start}, function(results, status) { var routeStart = new google.maps.Marker({ map: map, position: results[0].geometry.location, icon: './images/motorcycling.png', shadow: './images/motorcycling.shadow.png' }); }); geocoder.geocode( { 'address': end}, function(results, status) { var routeEnd = new google.maps.Marker({ map: map, position: results[0].geometry.location, icon: './images/motorcyclingend.png', shadow: './images/motorcycling.shadow.png' }); }); <?php $adverts = mysql_query("SELECT * FROM adverts WHERE ad_area = '$county' AND ad_visible='1' "); while($ad_row = mysql_fetch_array($adverts)){ $position = $ad_row[ad_postcode]; $type = $ad_row[ad_type]; echo "var position".$ad_row[ad_id]." = '".$position."'\n"; $ad_id = $ad_row[ad_id]; $pics = mysql_query("SELECT * FROM photos WHERE ad_id = '$ad_id' AND main_pic = '1'"); $pic_row = mysql_fetch_array($pics); $pic_name = $pic_row[photo_name]; $pic_name = str_replace(' ', '%20', $pic_name); ?> geocoder.geocode( { 'address': position<?php echo $ad_row[ad_id]; ?>}, function(results, status) { var marker<?php echo $ad_row[ad_id]; ?> = new google.maps.Marker({ map: map, position: results[0].geometry.location, <?php if ($type == 'accommodation'){ echo "icon: 'images/hotel.png'\n"; }elseif($type == 'fooddrink'){ echo "icon: 'images/bar.png'\n"; }elseif($type == 'essentials'){ echo "icon: 'images/motorcycle.png'\n"; } ?> }); var content = "<p><\a style='color:black;' href='./advert.php?advert=<?php echo $ad_row[ad_id]; ?>'><?php echo $ad_row[ad_company]; ?><\/a></p><img src='./thumbs/<?php echo $pic_name; ?>' />"; var infowindow<?php echo $ad_row[ad_id]; ?> = new google.maps.InfoWindow({ content: content }); google.maps.event.addListener(marker<?php echo $ad_row[ad_id]; ?>, "click", function() { infowindow<?php echo $ad_row[ad_id]; ?>.open(map,marker<?php echo $ad_row[ad_id]; ?>); }); }); Need help with this, has anyone does this before? Here is the tutorial I have been following: https://developers.google.com/maps/articles/phpsqlajax#outputxml The part I am on from the tutorial is where it says Checking that XML output works it is meant to display the data from the database but i just get a blank page, no data is shown from my database on the page? I just have a php file with the code from the tutorial. Hello! I am trying to find a way to assign the JSON value Google Map's API Returns when passed an address. I would search Google, but I am only a few month deep into PHP and really don't know what keywords to use. I really don't even know what a JSON is? Anyway, I found this article that explains how to query Google Maps with an address and have it return a GPS Location. When I tested it in my browser, the text appears. I just don't know what to use to take what the browser is displaying and assign in to an Object in a PHP page. This is the Google Maps Query: Code: [Select] http://maps.google.com/maps/geo?q="ADDRESS"&output=csv&oe=utf8 This my function where I want to use this: Code: [Select] //Querries Google Map's API with an address and assigns the returned GPS Location //to this Object public function build_me($this_address) { //Builds the query from the address array to send to the Goole Maps API $query = $this_address["Line1"].",".$this_address["Line2"].",". $this_address["City"].",".$this_address["State"].",".$this_address["Zip"]; //Location_Array = http://maps.google.com/maps/geo?q=$query&output=csv&oe=utf8 $this->latitude = //Location_Array['Something']; $this->longitude = //Location_Array['Something']; } This is the article that I am referring to: http://martinsikora.com/how-to-get-gps-coordinates-from-an-address My question is, how would I go about doing this? Are there any good tutorials on this? Thanks in advance for anyone pointing me in the right direction! Has anyone out there ever used PHP to grab the font information of a opentype or truetype font file? For example, create a character, glyph map of all the letter designs in a font? I see many font sites do this, but I have tried doing this with imagemagick, result was way to slow and crashed out most the time. Here are a few examples I have found of working examples: http://fontshop.com/fonts/font_rend.php?idt=f&id=224932&rbe=cmap&acs=1&acs_p=1&acs_pt=32 http://new.myfonts.com/fonts/boris-marinov/dimitrina/thin/characters.html Any ideas? I have been trying for months, no results yet.. I finally got my kml to display through the static maps api thinking I could then display my map on the pdf I'm generating using mpdf. But, it is not displaying the image in the pdf. It works fine on a blank test page.
$kmlMap = "<img src=\"http://maps.googleapis.com/maps/api/staticmap?zoom=15&size=500x300&maptype=hybrid&path=color:0xff0000ff|weight:3|$correctedCoords \" /><br />";Any ideas on how I could make this work with mpdf? Hi there, So the below code is working for 1 entry, however there is 2 entries in the database which are different postcodes and I cannot get to show in Google Maps. When I do it without Mysql and just do it direct it works, but really want to do it from MYSQL - both postcodes are valid and tested as well.
<?php $sql4 = "SELECT * FROM MK_migration_details"; $result4 = $conn->query($sql4); ?> function initialize() { geocoder = new google.maps.Geocoder(); var latlng = new google.maps.LatLng(40.768505,-111.853244); var myOptions = { mapTypeControl: false, fullscreenControlOptions: false, zoom: 8, center: latlng, mapTypeId: google.maps.MapTypeId.ROADMAP } map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); <?php while($row4 = $result4->fetch_assoc()) { $mig_postcode = $row4["postcode"]; } echo 'addPostCode("'.$mig_postcode.'")'; ?> } I know the issue lies with the PHP / Mysql Loop and the Javascript element 'addpostcode' when I put into the loop does not work, but works for a single address outside the loop.
Really appreciate your help guys!
Thanks you Hi, I currently have a google map which shows a marker where the postcode is for a certain pub (converts postcodes to coords lat/long) I would like to loop through all my pubs in my database as place a marker for each on one map, I am uncertain of how to loop through and show each marker for each postcode either PHP or JavaScript. here is my code for a single pub / postcode: Code: [Select] <!doctype html> <?php include "../config.php"; $loggedIn = (isset($_COOKIE['loggedin']) && $_COOKIE['loggedin'] == 'true')?true:false; $PUBID = intval($_REQUEST['PUBID']); $PUB = mysql_query("SELECT * FROM pubs WHERE PUBID = '".$PUBID."'"); $pubdetails = mysql_fetch_array($PUB); ?> <html> <head> <meta charset="UTF-8" /> <title><?php echo $pubdetails['rsPubName']; ?>, <?php echo $pubdetails['rsTown']; ?>, <?php echo $pubdetails['rsCounty']; ?></title> <style type="text/css" media="screen">@import "jqtouch/jqtouch.min.css";</style> <style type="text/css" media="screen">@import "themes/jqt/theme.min.css";</style> <script src="jqtouch/jquery.1.3.2.min.js" type="text/javascript" charset="utf-8"></script> <script src="jqtouch/jqtouch.min.js" type="application/x-javascript" charset="utf-8"></script> <script src="http://maps.google.com/maps?file=api&v=2&sensor=true&key=ABQIAAAAM17e4xGXwO4sBd_QYtRiSRQXB4T7UHWaz4zUQgLx9muJZW0c3hS8jRMJg733CHqOihn7BVfhZTkLiA" type="text/javascript"></script> <script type="text/javascript"> function initialize() { var latlng = new google.maps.LatLng(-34.397, 150.644); var myOptions = { zoom: 8, center: latlng, mapTypeId: google.maps.MapTypeId.G_NORMAL_MAP }; var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); } </script> <script type="text/javascript" charset="utf-8"> var jQT = new $.jQTouch({ icon: 'jqtouch.png', addGlossToIcon: false, startupScreen: 'jqt_startup.png', statusBar: 'black', preloadImages: [ 'themes/jqt/img/back_button.png', 'themes/jqt/img/back_button_clicked.png', 'themes/jqt/img/button_clicked.png', 'themes/jqt/img/grayButton.png', 'themes/jqt/img/whiteButton.png', 'themes/jqt/img/loading.gif' ] }); </script> </head> <body onLoad="ukPostcodeTest(); return false"> <!-- TOWNS --> <div id="pub" class="current"> <div class="toolbar"> <h1>View Pub</h1> <a class="back" href="index.php" rel="external">Home</a> </div> <h2><?php echo $pubdetails['rsPubName']; ?></h2> <?php echo $pubdetails['rsAddress']; ?><br /> <?php echo $pubdetails['rsTown']; ?><br /> <?php echo $pubdetails['rsCounty']; ?><br /> <?php echo $pubdetails['rsPostCode']; ?><br /> <?php echo $pubdetails['Region']; ?><br /> <?php echo $pubdetails['rsTel']; ?><br /> <?php echo '<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.mypubspace.com/pub_info.php?PUBID='.$pubdetails['PUBID'].'&layout=box_count&show_faces=true&width=450&action=like&colorscheme=light&height=65" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:60px; height:65px; float:right;" allowTransparency="true"></iframe>';?> <div id="map" style="width: 250px; height: 250px"></div> <form name="mapform" onsubmit="ukPostcodeTest(); return false" action="#"> <input id="search" type="hidden" value="<?php echo $pubdetails["rsPostCode"]; ?>" /> </form> <div id="message"></div> <noscript><b>JavaScript must be enabled in order for you to use Google Maps.</b> However, it seems JavaScript is either disabled or not supported by your browser. To view Google Maps, enable JavaScript by changing your browser options, and then try again. </noscript> <script type="text/javascript"> //<![CDATA[ if (GBrowserIsCompatible()) { var map = new GMap(document.getElementById("map")); map.addControl(new GLargeMapControl()); map.addControl(new GMapTypeControl()); map.setCenter(new GLatLng(51.520593197675446,-0.19775390625),16); // ====== Is the search string a UK Postcode ====== function ukPostcodeTest() { var search = document.getElementById("search").value; // take a copy and convert to upper case var s = search.toUpperCase(); // Replace punctuation and whitepsace by a single space s = s.replace(/\W+/g, " "); // Remove and trailing leading spaces s = s.replace(/^ /, ""); s = s.replace(/ $/, ""); // Perform the check var match = s.match(/^[A-Z]{1,2}[0-9R][0-9A-Z]? [0-9][ABD-HJLNP-UW-Z]{2}$/); if (!match) { // Its not a UK Postcode, so perform a standard GClientGeocoder call on the original search string showAddress(search); } else { // It is a UK Postcode, so call GDirections on the reformatted search string showPostcode(s); } } // ====== Code for handling search strings that are not UK Postcodes ======= // ====== Use the GClientGeocoder in the normal way ====== // ====== Create a Client Geocoder ====== var geo = new GClientGeocoder(); // ====== Array for decoding the failure codes ====== var reasons=[]; reasons[G_GEO_SUCCESS] = "Success"; reasons[G_GEO_MISSING_ADDRESS] = "Missing Address: The address was either missing or had no value."; reasons[G_GEO_UNKNOWN_ADDRESS] = "Unknown Address: No corresponding geographic location could be found for the specified address."; reasons[G_GEO_UNAVAILABLE_ADDRESS]= "Unavailable Address: The geocode for the given address cannot be returned due to legal or contractual reasons."; reasons[G_GEO_BAD_KEY] = "Bad Key: The API key is either invalid or does not match the domain for which it was given"; reasons[G_GEO_TOO_MANY_QUERIES] = "Too Many Queries: The daily geocoding quota for this site has been exceeded."; reasons[G_GEO_SERVER_ERROR] = "Server error: The geocoding request could not be successfully processed."; // ====== Geocoding ====== function showAddress(search) { // ====== Perform the Geocoding ====== geo.getLocations(search, function (result) { // If that was successful if (result.Status.code == G_GEO_SUCCESS) { // How many resuts were found document.getElementById("message").innerHTML = "Found " +result.Placemark.length +" results"; // Loop through the results, placing markers for (var i=0; i<result.Placemark.length; i++) { var p = result.Placemark[i].Point.coordinates; var marker = new GMarker(new GLatLng(p[1],p[0])); document.getElementById("message").innerHTML += "<br>"+(i+1)+": "+ result.Placemark[i].address + marker.getPoint(); map.addOverlay(marker); } // centre the map on the first result var p = result.Placemark[0].Point.coordinates; map.setCenter(new GLatLng(p[1],p[0]),14); } // ====== Decode the error status ====== else { var reason="Code "+result.Status.code; if (reasons[result.Status.code]) { reason = reasons[result.Status.code] } alert('Could not find "'+search+ '" ' + reason); } } ); } // ====== Create a Client Geocoder ====== var gdir = new GDirections(null); // ====== Using GDirections to process a UK postcode ====== function showPostcode(search) { // Call GDirections gdir.loadFromWaypoints([search,search],{getPolyline:true}); // Wait for the reply to come back GEvent.addListener(gdir,"load", function() { var poly = gdir.getPolyline(); var point = poly.getVertex(0); //document.getElementById("message").innerHTML = "Found a UK Postcode"; // Process the result var marker = new GMarker(point); //document.getElementById("message").innerHTML += "<br>" + search + " = " + point.toUrlValue(5); map.addOverlay(marker); // centre the map on the result map.setCenter(point,16); }); } } // display a warning if the browser was not compatible else { alert("Sorry, the Google Maps API is not compatible with this browser"); } // This Javascript is based on code provided by the // Community Church Javascript Team // http://www.bisphamchurch.org.uk/ // http://econym.org.uk/gmap/ //]]> </script> </div> </body> </html> |