Jump to content

yahoo help needed


smith.james0

Recommended Posts

I am trying to get the longitude and latitude from yahooapis using

 

http://query.yahooapis.com/v1/public/yql?q=select%20centroid%20from%20geo.places%20where%20text%3D%22$postcode%2Cuk%22&diagnostics=true

 

where $postcode is a uk postcode, but I get nothing.

 

I know it's something simple but I can't get it to work  :confused:


$doc = new DOMDocument();
$doc->load("http://query.yahooapis.com/v1/public/yql?q=select%20centroid%20from%20geo.places%20where%20text%3D%22$postcode%2Cuk%22&diagnostics=true");
$channel = $doc->getElementsByTagName("*");
$info = array();
foreach($channel as $element)
                {
             // Condition
             if($element->localName == "centroid")
			{
				$latlongpostcode['latitude'] = $element->getElementsByTagName("latitude");
				$latlongpostcode['longitude'] = $element->getElementsByTagName("longitude");
				
			}
	
				}
				
				

}
print_r($latlongpostcode);
<?xml version="1.0" encoding="UTF-8"?>
<query xmlns:yahoo="http://www.yahooapis.com/v1/base.rng"
    yahoo:count="1" yahoo:created="2013-05-21T16:19:29Z" yahoo:lang="en-US">
    <diagnostics>
        <publiclyCallable>true</publiclyCallable>
        <url execution-start-time="1" execution-stop-time="135" execution-time="134"><![CDATA[http://where.yahooapis.com/v1/places.q(wa37pq%2C%20uk);start=0;count=10]]></url>
        <user-time>136</user-time>
        <service-time>134</service-time>
        <build-version>36794</build-version>
    </diagnostics> 
    <results>
        <place xmlns="http://where.yahooapis.com/v1/schema.rng">
            <centroid>
                <latitude>53.414478</latitude>
                <longitude>-2.525600</longitude>
            </centroid>
        </place>
    </results>
</query>

Any help would be great full 

James

Link to comment
Share on other sites

Not sure if it's the best way but I have got it to work  :happy-04:

$postcode = str_replace(' ','',$postcode);

$doc = new DOMDocument();
$doc->load("http://query.yahooapis.com/v1/public/yql?q=select%20centroid%20from%20geo.places%20where%20text%3D%22$postcode%2Cuk%22&diagnostics=true");

$channel = $doc->getElementsByTagName("*");

$info = array();

foreach($channel as $element)
                {
             // Condition
             if($element->localName == "centroid")
			{
				$latlongpostcode['latitude'] = $element->getElementsByTagName('latitude')->item(0)->nodeValue;
				$latlongpostcode['longitude'] = $element->getElementsByTagName('longitude')->item(0)->nodeValue;
				
			}
	
				}			

}
Link to comment
Share on other sites

or

$xml = simplexml_load_file("http://query.yahooapis.com/v1/public/yql?q=select%20centroid%20from%20geo.places%20where%20text%3D%22$postcode%2Cuk%22&diagnostics=true");

$location = (array)$xml->results->place->centroid;

/**** RESULT ***************
$location = Array
(
    [latitude] => 54.375240
    [longitude] => -2.594900
)

****************************/

Edited by Barand
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.