Latitude, longpolling, PHP and the Yahoo geocoder PHP get geographic latitude and longitude through Yahoo geocoder

Source: Internet
Author: User

I was doing some work with the Google Maps API yesterday and I needed to convert an address, like 1807 Hendricks Ave. jacksonville, FL 32207, to latitude and long1_points. having a latitude and longpolling is the only way you can plot points on a Google Map.

There are two popular geocoding services, geocoder. us and Yahoo's geocoding service. I decided to use Yahoo's because Yahoo has a better interface than the geocoding. US site. good reason huh ?!

Yahoo's service returns latitude and long1_points in one of two ways. You can choose which one you wowould like to use.

  1. XML document
  2. Serialized PHP

I decided to use serialized PHP because I have never worked with it and I wanted to try it out. Here is how I extracted the latitude and longpolling Out Of The serialized PHP Data.

The Yahoo! Web Services request(Line breaks added for legibility, it shocould be one long string in your code)Note: If you use this for anything other than a demo you need to get your own appid. Right now we are using the yahoodemo appid

$req = 'http://api.local.yahoo.com/MapsService/V1/geocode?appid=YahooDemo&street=1807+Hendricks+Avenue&city=Jacksonville&state=FL&output=php';

Make the request

$phpserialized = file_get_contents($req);

Parse the serialized response

$phparray = unserialize($phpserialized);

Now we have to extract the data from the variable $ phparray

$ Phparray contains another array called resultset [], which contains another array called result [], which contains the longpolling and latitude data. confusing as hell I know, but that's what we have to work. here is an example data structure.

Step 1: Get the data in the resultset [] array and store it in a variable

$resultset = $phparray[ResultSet];

Step 2: Get the data in the result [] array and store it in a variable

$result = $resultset[Result];

Step 3: now simply extract the longpolling and latitude data

$Latitude = $result[Latitude];$Longitude = $result[Longitude];

Step 4: You are done!

Now you can use the latitude and longpolling to plot points on Google maps using the Google Maps API.

Please comment if you can improve on this code or if you have any questions on the Yahoo geocoder or the Google Maps API. I am no expert, but I will help if I can.

Source:

Http://www.ngenworks.com/blog/detail/latitude_longitude_php_and_the_yahoo_geocoder/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.