Presentation is loading. Please wait.

Presentation is loading. Please wait.

Creating Databases Example using Google Maps API + file creation. Dollar sign problem. Classwork/Homework: [catch up]. Work on final project.

Similar presentations


Presentation on theme: "Creating Databases Example using Google Maps API + file creation. Dollar sign problem. Classwork/Homework: [catch up]. Work on final project."— Presentation transcript:

1 Creating Databases Example using Google Maps API + file creation. Dollar sign problem. Classwork/Homework: [catch up]. Work on final project

2 Google Maps example Challenge: create list of positions defining polygon(s) for a quiz (or something else) Solution: – Create.html and.php pair of scripts to create file – Create drawing program using the file created. Recreates inserting name of file Note: student's project will still need work on file, namely combining multiple files into one.

3 Scripts http://socialsoftware.purchase.edu/jeanine.m eyer/createFileOfLocations.html http://socialsoftware.purchase.edu/jeanine.m eyer/createFileOfLocations.html This creates a file with the name specified by the user. The following file has a file name hard coded in it: http://socialsoftware.purchase.edu/jeanine.m eyer/drawpolygon2.html http://socialsoftware.purchase.edu/jeanine.m eyer/drawpolygon2.html

4 About the html file Mouse clicks on map add to an array A form invokes a client side function "sendit()" using onsubmit and then the server side writeoutlatlongs.php using action The form also requests a name for the file.

5 Html script var map; var redx = "rx1.png"; function init() { blatlng = new google.maps.LatLng(41.04966,-73.70361); myOptions = { zoom: 17, center: blatlng, mapTypeId: google.maps.MapTypeId.SATELLITE }; map = new google.maps.Map(document.getElementById("place"), myOptions); listener = google.maps.event.addListener(map, 'click', function(event) { checkit(event.latLng);}); }

6 Html script, cont. var elements = []; var markersArray = []; function sendit() { var data = elements.join(':'); //alert("in sendit, data is "+data); document.f.positions.value = data; return false; } function checkit(clatlng) { lastmarker = clatlng; marker = new google.maps.Marker({ position: clatlng, icon: redx, map: map }); markersArray.push(marker); pos = "["+String(clatlng.lat())+", "+String(clatlng.lng())+"]"; elements.push(pos); //alert("position is "+pos+" and number of elements is "+elements.length); }

7 Html script, cont.: body Mark polygon When done inserting points, accept or enter name of area to be used as file name and click on Done. Your name for the polygon

8 php script <?php $newname = $_GET['subject']; $positions = $_GET['positions']; $filen ="uploads/". $newname. ".js" ; $open = fopen($filen,"w"); print (" Saving positions in $filen "); //explode into array $positions = explode(":",$positions); //now write out each pair as line in file $open = fopen($filen,"w");

9 php script, cont. if ($open) { fwrite($open,"var positions = [ \n"); for($i=0;$i<count($positions)-1;$i++) { fwrite($open,$positions[$i].",\n"); } fwrite($open,$positions[$i]."\n "); // omit comma after last element fwrite($open,"]; \n"); fclose($open); } else { print (" Unable to write updated file. "); } ?>

10 myplace.js var positions = [ [41.04975269410072, -73.70332717895508], [41.050230063741964, -73.70357394218445], [41.05012488089815, -73.70411038398743], [41.04962323732983, -73.70400309562683], [41.04946141600802, -73.70352029800415] ];

11 Draw script You can view source. http://socialsoftware.purchase.edu/jeanine.meyer/drawpolyg on2.html http://socialsoftware.purchase.edu/jeanine.meyer/drawpolyg on2.html Makes use of Google Maps API google.maps.Polygon and google.maps.Infowindow Robust system could include facility for editing positions.

12 What if… CTS assigned you a password with a dollar sign in it. Two solutions (say password was abc$def – Use single quotes: $password = ‘abc$def’ – Escape character: $password = “abc\$def’ Can use this in other situations. http://socialsoftware.purchase.edu/jeanine.m eyer/dollartest.php http://socialsoftware.purchase.edu/jeanine.m eyer/dollartest.php

13 <?php $stringWdollar = 'abc$def'; print ("string with single quotes ".$stringWdollar); print(" "); $stringWdollarescaped = "abc\$def"; print ("string with dollar sign escaped ".$stringWdollarescaped); print (" "); $stringWdollarescapedsinglequotes = 'abc\$def'; print ("string with dollar sign escaped, single quotes ".$stringWdollarescapedsinglequotes); print (" "); $stringWdollarplain = "abc$def"; print ("string with dollar, double quotes ".$stringWdollarplain); ?>

14 Classwork/homework [Catch up with postings, showing work.] [Evaluation surveys.] Prepare to show something on final project.


Download ppt "Creating Databases Example using Google Maps API + file creation. Dollar sign problem. Classwork/Homework: [catch up]. Work on final project."

Similar presentations


Ads by Google