tags:

views:

23

answers:

2

Hi! I am trying to extract the latitude and longitude of a google maps url. Such an url could look like this:

$url = 'http://maps.google.com/?ie=UTF8&ll=39.811856,11.309322&spn=0,0.485802&t=h&z=12&layer=c&cbll=39.311856,11.519322&panoid=1hltSSOoqv5H1dVKZWFkaA&cbp=13,117.95,,1,16.71';

As you can see, there's several location sets in the url. The cbll variable seems to be the right one in my case.

This is what I came up with:

preg_match("~&cbll=(-?\d+\.?\d*),(-?\d+\.?\d*)~", $url, $matches);

The problem: The preg_match seems to match the first '&ll=' in the url, and not the cbll part. I get the "&ll=" part of the url as result.

+1  A: 
parse_str(parse_url($url, PHP_URL_QUERY), $vars);
list($a, $b) = explode(",", $vars['cbll']);
Artefacto
+1  A: 

It works for me, if I var_dump $matches, I see this

array(3) {
  [0]=>
  string(25) "&cbll=39.311856,11.519322"
  [1]=>
  string(9) "39.311856"
  [2]=>
  string(9) "11.519322"
}
Paul Dixon
You are right. Should have checked the var_dump.Now I need to find out why there is a marker showing in my map at the location of the ll variable, but not at the cbll variable...
reggie