Google mapping

Discussion in 'Programming' started by Jim bob 9 pants, Mar 24, 2006.

  1. #1
    How can I convert UK postal codes into a Gpoint for google mapping?

    I am going around in circles on this one

    Jamie


    EDIT - JUST FOUND SOME GEO CODERS but anyone who has any tips, I am sure I will soon be out of my depth
     
    Jim bob 9 pants, Mar 24, 2006 IP
  2. Jim bob 9 pants

    Jim bob 9 pants Peon

    Messages:
    890
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Oh well no help so far - I have done the above, now I have a data base of let and longs, a web page with the map on it, now How do I get the data from the data base and add it to the map dynamically??
     
    Jim bob 9 pants, Mar 25, 2006 IP
  3. mad4

    mad4 Peon

    Messages:
    6,986
    Likes Received:
    493
    Best Answers:
    0
    Trophy Points:
    0
    #3
    You should start by creating a map with just one point on it and learning about the map API.

    Once you have done this you just need to use PHP to loop through the results and output the required code.
     
    mad4, Mar 27, 2006 IP
  4. stuw

    stuw Peon

    Messages:
    702
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    0
    #4
    use a service like www.postcodeanywhere.co.uk to convert your postcodes to latitude and lontitude on the fly. store the lat and long from the postcodes in a database so you don't need to look them up each time. Use the lat and long to make your gmap.

    Is what I use with postcode anywhere:

    global $ACCOUNTCODE,$LICENSEKEY;
    $ACCOUNTCODE = "xxxxxxxxxxxxxxx";
    $LICENSEKEY = "xxxxxxxxxxxxxxxxx";
    
    $OriginPostcode=$_GET['p'];
    
    
    // look up
    // is this postcode already recorded?
    $checkcode=str_replace(' ','',$OriginPostcode);
    $sql="select lat, lon from coords where postcode='".mysql_real_escape_string($checkcode)."'";
    // echo $sql;
    $result=mysql_query($sql,$db);
    if (mysql_num_rows($result)==0) {
    	// postcode not already in db, look up
    	// get the postcode
    	$sURL = "http://services.postcodeanywhere.co.uk/recordset.aspx?";
    	$sURL .= "account_code=" . urlencode($ACCOUNTCODE);
    	$sURL .= "&license_code=" . urlencode($LICENSEKEY);
    	$sURL .= "&action=nearest";
    	$sURL .= "&origin=" . urlencode($checkcode);
    	$sURL .= "&destination=" . urlencode($checkcode);
    	$ContentsXXX=file("$sURL");
    	foreach ($ContentsXXX as $line_num => $line) {
    		if (strpos($line,"<z:row")!==false) { $Contents[]= $line; }
    	}
    	for ($i=0;$i<count($Contents);$i++) {
    		$Contents[$i]=ltrim(rtrim($Contents[$i]));
    		$Contents[$i]=str_replace("\"","",$Contents[$i]);
    		$breakapart=explode(" ",$Contents[$i]);
    		// convert the results into $variables
    		foreach ($breakapart as $value){
    			list($k,$v)=explode("=",$value);
    			${$k}=$v;
    	 	} // end foreach
    	}
    
    	// end look up
    	// store the results in the db
    	$sql="insert into coords (postcode,lat,lon) values ('$checkcode','$latitude','$longitude')";
    	// echo $sql;
    	mysql_query($sql,$db);
    
    	} else {
    	// postcode was found in mapping database
    	$data=mysql_fetch_array($result);
    	$latitude=$data['lat'];
    	$longitude=$data['long'];
    	// echo $latitude;
    }
    Code (markup):
     
    stuw, Mar 27, 2006 IP
  5. Jim bob 9 pants

    Jim bob 9 pants Peon

    Messages:
    890
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thanks guys, great help - think I have done it now, just tweaking the little boxes now.
     
    Jim bob 9 pants, Mar 27, 2006 IP