lloydio Posted May 3, 2006 Share Posted May 3, 2006 What i want to do is dynamicly plot the postcodes onto the map and the array to split on , from the query string.how i would of thought it would of worked by having $settings[postcodes] = array($_GET['markercode']);and querystring ?markercode="BH1", "BH2", "UB3", "UB4", "UB4", "UB4", "UB5", "UB4"but doing it this way it just ignors the ,please could anyone lend a hand. [u]heres the code:[/u][!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]<?php/////////////////////////////////////////////////////// Google Maps API with Jibble UK Postcodes v1.0 //// sebflipper Copyright 2005 //// [a href=\"http://www.sebflipper.com\" target=\"_blank\"]http://www.sebflipper.com[/a] //// //// As Google Maps only works from longitude and //// latitude decimal notations use this script to //// work out marker positions using the first part //// of the UK Postcode //// //// Please refer to readme.txt for more details //// //// Distributed under the terms of the //// General Public License (GPL) See: //// [a href=\"http://www.gnu.org/copyleft/gpl.html\" target=\"_blank\"]http://www.gnu.org/copyleft/gpl.html[/a] //// //// Google Maps and/or the Jibble UK Postcode //// Database may operate under a different //// licenses, please see their sites for info ///////////////////////////////////////////////////////// Report all errors except E_NOTICE// This is the default value set in php.inierror_reporting(E_ALL ^ E_NOTICE); // Config Area// MySQL connection details$settings[server] = 'geton2.gotadsl.co.uk';$settings[db_name] = 'postcode';$settings[db_user] = 'postcode';$settings[db_pass] = 'postcode123123';// Your Google Maps key (get one for free from: [a href=\"http://www.google.com/apis/maps/signup.html)\" target=\"_blank\"]http://www.google.com/apis/maps/signup.html)[/a]$settings[google_maps_key] = 'ABQIAAAAjf0IkBr7AhZMIHENI_tmMxQnXaCp8Z41NECtBqyfmMrZtmeT1RQ_HfMypmP4Lkcc2TJw-l_tNA5qMg'; // Key for: [a href=\"http://127.0.0.1/\" target=\"_blank\"]http://127.0.0.1/[/a]// Starting Postcode (Postcode to centerAndZoom from)$settings[start_postcode] = $_GET['postcode'];$settings[zoom_level] = "5";$settings[div_style] = "width: 12em; style: font-size: small";// Postcodes to show as markers (this would most likely come from your database or from the users $_GET or $_POST, but as an example I have fill out some postcodes)//$settings[postcodes] = array($_GET['markercode']);$settings[postcodes] = array("BH1", "BH2", "UB3", "UB4", "UB4", "UB4", "UB5", "UB4");//array("UB8", "UB7", "UB3", "UB4", "UB4", "UB4", "UB5", "UB4")$settings[postcode_html] = array($_GET['markertxt']);// Longitude and Latitude Markers (if you need to use a more precise location)$settings[long_lat] = array("-0.472219,51.509878");$settings[long_lat_html] = array("West Drayton Station");//////////////////////// End of Config Area// Connect to database$db = mysql_connect($settings[server], $settings[db_user], $settings[db_pass]) or die("<hr>Unable to connect to database on '".$settings[server]."' with user '".$settings[db_user]."'<br />Please check your settings in this file"); mysql_select_db($settings[db_name],$db) or die("Please first create your database '".$settings[db_name]."'!"); ;?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"> <head> <style type="text/css"> <!-- body { font-family: Arial, Helvetica, sans-serif; font-size: small; } --> </style> <script src="http://maps.google.co.uk/maps?file=api&v=1&key=<?php echo $settings[google_maps_key]; ?>" type="text/javascript"></script> </head> <body> <!-- Google Maps API with Jibble UK Postcodes v1.0 - sebflipper Copyright 2005 - [a href=\"http://www.sebflipper.com\" target=\"_blank\"]http://www.sebflipper.com[/a] !--> <div id="map" style="width: 500px; height: 400px"></div> <script type="text/javascript"> //<![CDATA[ // Load up Google Maps var map = new GMap(document.getElementById("map")); map.addControl(new GSmallMapControl()); map.addControl(new GMapTypeControl()); <?php // Get starting cords $sql_query = "SELECT * FROM `postcode_data` WHERE `postcode` LIKE '$settings[start_postcode]' LIMIT 0 , 1"; //echo $sql_query; $result = mysql_query($sql_query,$db); if ($data = mysql_fetch_array($result)) { do { $longitude = $data[long_dec]; $latitude = $data[lat_dec]; } while ($data = mysql_fetch_array($result)); } echo "map.centerAndZoom(new GPoint($longitude,$latitude), $settings[zoom_level]);\n\n"; ?> function createMarker(point,html) { var marker = new GMarker(point); GEvent.addListener(marker, "click", function () { marker.openInfoWindowHtml(html); }); return marker; } <?php // Check if there are any postcodes the same and merge there HTML content $key_index_merge = -1; foreach ($settings[postcodes] as $postcode) { $key_index_merge++; $found_key = array_search($postcode, $settings[postcodes]); if ($key_index_merge !== $found_key) { // Remove the key unset($settings[postcodes][$found_key]); // Take the HTML and add it to existing key $new_key = array_search($postcode, $settings[postcodes]); $settings[postcode_html][$new_key] = $settings[postcode_html][$new_key]."<br><!-- New Postcode !-->".$settings[postcode_html][$found_key]; // Remove the old HTML unset($settings[postcode_html][$found_key]); } } // Reindex arrays $settings[postcodes] = array_values($settings[postcodes]); $settings[postcode_html] = array_values($settings[postcode_html]); // Count how many items are shown in each box $key_index_count = -1; foreach ($settings[postcode_html] as $postcode_html) { $key_index_count++; $items = explode("<!-- New Postcode !-->", $postcode_html); $no_items = count($items); $settings[postcode_html][$key_index_count] = "<b>$no_items</b> location(s) found:<br>".$settings[postcode_html][$key_index_count]; } // Postcode Markers $key_index = -1; //$settings[postcodes] = array_unique($settings[postcodes]); foreach ($settings[postcodes] as $postcode) { $key_index++; $sql_query = "SELECT * FROM `postcode_data` WHERE `postcode` LIKE '$postcode' LIMIT 0 , 1"; $result = mysql_query($sql_query,$db); if ($data = mysql_fetch_array($result)) { do { $longitude = $data[long_dec]; $latitude = $data[lat_dec]; } while ($data = mysql_fetch_array($result)); } echo "\nvar point = new GPoint($longitude,$latitude);\n"; echo "var marker = createMarker(point, \"<div style='$settings[div_style]'>".$settings[postcode_html][$key_index]."</div>\");\n"; echo "map.addOverlay(marker);\n"; } // Longitude and Latitude Markers $key_index = -1; foreach ($settings[long_lat] as $long_lat) { $key_index++; echo "\nvar point = new GPoint($long_lat);\n"; echo "var marker = createMarker(point, \"<div style='$settings[div_style]'>".$settings[long_lat_html][$key_index]."</div>\");\n"; echo "map.addOverlay(marker);\n"; } ?> //]]> </script> </body></html>[/quote]thanksLloyd Quote Link to comment https://forums.phpfreaks.com/topic/8979-google-map/ Share on other sites More sharing options...
ober Posted May 3, 2006 Share Posted May 3, 2006 Where is the array of values coming from and how are you passing it? Quote Link to comment https://forums.phpfreaks.com/topic/8979-google-map/#findComment-33004 Share on other sites More sharing options...
lloydio Posted May 4, 2006 Author Share Posted May 4, 2006 [!--quoteo(post=370952:date=May 3 2006, 06:06 PM:name=ober)--][div class=\'quotetop\']QUOTE(ober @ May 3 2006, 06:06 PM) [snapback]370952[/snapback][/div][div class=\'quotemain\'][!--quotec--]Where is the array of values coming from and how are you passing it?[/quote]well i would like the array of values to come from a querystring. if the array data is hard coded then it will work.[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]$settings[postcodes] = array("BH1", "BH2", "UB3", "UB4", "UB4", "UB4", "UB5", "UB4");[/quote]if i use[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]$settings[postcodes] = array($_GET['markercode']);[/quote]and had "BH1", "BH2", "UB3", "UB4", "UB4", "UB4", "UB5", "UB4" in my querystring. then the whole line "BH1", "BH2", "UB3", "UB4", "UB4", "UB4", "UB5", "UB4" appears first in the array without being broken up by the , .im thinking i need to convert the querystring result into a format the array can use. Quote Link to comment https://forums.phpfreaks.com/topic/8979-google-map/#findComment-33231 Share on other sites More sharing options...
kenrbnsn Posted May 4, 2006 Share Posted May 4, 2006 Where is the URL being generated? Is it coming from a form? Another script?Having quoted strings in a URL is fairly unusual. The url should look like[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]?markercode=BH1, BH2, UB3, UB4, UB4, UB4, UB5, UB4[/quote]The the processing script would see that value of $_GET['markercode'] is the string "BH1, BH2, UB3, UB4, UB4, UB4, UB5, UB4".Then you could do[code]<?php $settings[postcodes] = explode(',', $_GET['markercode']);[/code]Ken Quote Link to comment https://forums.phpfreaks.com/topic/8979-google-map/#findComment-33326 Share on other sites More sharing options...
lloydio Posted May 5, 2006 Author Share Posted May 5, 2006 [!--quoteo(post=371279:date=May 4 2006, 03:59 PM:name=kenrbnsn)--][div class=\'quotetop\']QUOTE(kenrbnsn @ May 4 2006, 03:59 PM) [snapback]371279[/snapback][/div][div class=\'quotemain\'][!--quotec--]Where is the URL being generated? Is it coming from a form? Another script?Having quoted strings in a URL is fairly unusual. The url should look likeThe the processing script would see that value of $_GET['markercode'] is the string "BH1, BH2, UB3, UB4, UB4, UB4, UB5, UB4".Then you could do[code]<?php $settings[postcodes] = explode(',', $_GET['markercode']);[/code]Ken[/quote]Great ;) worked a treat, thank you very much Quote Link to comment https://forums.phpfreaks.com/topic/8979-google-map/#findComment-33514 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.