Jump to content

Recommended Posts

<?php
// three parts to the querystring: q is address, output is the format, key is the GAPI
$key = 'your key';
$location = 'singapore'
$url = 'http://maps.google.com/maps/geo?q='.urlencode($location).'&output=xml&key='.$key;

sleep(1);


$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER,0);
curl_setopt($ch, CURLOPT_VERBOSE,0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_FRESH_CONNECT,1);
// I'm telling google maps im using Chrome because this process will be automated in future uses 
curl_setopt($ch, CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US) AppleWebKit/525.19 (KHTML, like Gecko) Chrome/0.3.154.9 Safari/525.19');

// capture anything in output so script wont break
ob_start();
$xml = curl_exec($ch);
ob_get_clean();

// check for errors
$error = curl_error($ch);

echo $xml;

?>

 

 

Result below

Queensland, Australia 200 geocode

Queensland, Australia

AUAustraliaQLD 145.774,-19.70

 

How to break apart the echo $xml so that one variable is longitude only, one variable is latitude only. Do you have any javascript to recommend also? Thank

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.