Jump to content

Parse long and lat from multimap


shocker-z

Recommended Posts

Is there a way that i would be able to parse the information 52.9767 and -1.0986 from the following lines? well from the entire page source?

<dl class="geo">
<dt>Lat:</dt>

<dd class="latitude">52:58:36N (52.9767)</dd>
<dt>Lon:</dt>
<dd class="longitude">1:05:55W (-1.0986)</dd>
</dl>

Or no of any ready made scripts?

Regards
Liam
Link to comment
https://forums.phpfreaks.com/topic/31776-parse-long-and-lat-from-multimap/
Share on other sites

I'd use strpos() to find <dd class="latitude"> then again to find the next occurrence </dd> following that.

Use substr() to extract the intervening text.

Repeat the process on the extracted text to get the text between "(" and ")".

Similarly for the longitude
hmm ive just got round to playting wiht it and thought to start with i would create just a litle block of code to size it down faster as </dd> occurs alot before the position i want.

The code below starts in the correct position but it echo's right to the bottom of the page??

[code]<?php
$multimap=file_get_contents('http://www.multimap.com/map/browse.cgi?client=public&search_result=&db=pc&lang=&keepicon=true&pc=NG43QN&advanced=&client=public&addr2=&quicksearch=ng43qn&addr3=&addr1=');

$place1=strpos($multimap,'<dt>Lat:</dt>');
$place2=strpos($multimap,'<dt>Web Address:</dt>');

echo 'long1: '.$place1.'<Br>';
echo 'long2: '.$place2.'<Br>';


echo substr($multimap, $place1, $place2);

?>[/code]

can see how it displays @ [url=http://www.ukchat.ws/engineers/untitled2.php]http://www.ukchat.ws/engineers/untitled2.php[/url]

Regards
Liam
BTW, the third arg of strpos is the position to search from, so

[code]<?php
$pos1 = strpos ($multimap, '<dd class="latitude">');
$pos2 = strpos ($multimap, '</dd>', $pos1);              // srch from pos1

echo substr($multimap, $pos1+21, $pos2-($pos1+21));    // allow for length of first string

?>[/code]
-->
52:58:36N (52.9767)
Cheers mate, heres the full code for anyone that needs it :)


[code]<form id="form1" name="form1" method="post" action="">
  Enter Postcode:
  <input name="postcode" type="text" id="postcode" />
  <input type="submit" name="Submit" value="Submit" />
</form>

<?php
if (isset($_POST['postcode'])) {

$multimap=file_get_contents('http://www.multimap.com/map/browse.cgi?client=public&search_result=&db=pc&lang=&keepicon=true&pc='.$_POST['postcode'].'&advanced=&client=public&addr2=&quicksearch=ng43qn&addr3=&addr1=');

$place1=strpos($multimap,'<dt>Lat:</dt>');
$place2=strpos($multimap,'<dt>Web Address:</dt>');
$latlon = substr($multimap, $place1, $place2-$place1);


//latitude
$lat1 = strpos ($latlon, '<dd class="latitude">');
$lat2 = strpos ($latlon, '</dd>', $lat1);
$lat = substr($latlon, $lat1+21, $lat2-($lat1+21));


$latitude1 = strpos ($lat, '(');
$latitude2 = strpos ($lat, ')', $latitude1);
$latitude = substr($lat, $latitude1+1, $latitude2-($latitude1+1));

//longditude
$lon1 = strpos ($latlon, '<dd class="longitude">');
$lon2 = strpos ($latlon, '</dd>', $lon1);
$lon = substr($latlon, $lon1, $lon2-$lon1);

$longitude1 = strpos ($lon, '(');
$longitude2 = strpos ($lon, ')', $longitude1);
$longitude = substr($lon, $longitude1+1, $longitude2-($longitude1+1));

echo 'Lon: '.$longitude.'<Br>';
echo 'Lat: '.$latitude.'<Br>';
}
?>[/code]


Regards
Liam

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.