Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

restful service getValues -- I cant get any values

Go to End

3 Posts   1516 Views


Community Member, 103 Posts

8 January 2011 at 8:42am

I'm trying to use restful service with google maps to get the latitude and longitude of a given address.

function onBeforeWrite(){
        $map = new RestfulService(",+Mountain+View,+CA&sensor=false", 0);
        //$coordinates = $map->getValues($xmlResponse,"location");
        //$lat = $map->getValues($xmlResponse,"GeocodeResponse_result_geometry_location","lat");
        //$long = $map->getValues($xmlResponse,"result_geometry_location","lng");


None of the commented getValues() above returns anything but null--obviously I've tried several different ways. The xml response is along the lines of (full response here):

<a lot of address components the same level as geometry></a lot of address components the same level as geometry>
<a lot of address components the same level as geometry></a lot of address components the same level as geometry>

What am i doing wrong?
Thank you!


Forum Moderator, 1391 Posts

10 January 2011 at 12:53am

Edited: 10/01/2011 12:54am

I' got this to work using the RestfulService::searchValue() method instead of getValues(). This is a little testversion I did in my Page_Controler (using your location :-) ):

       function RestfulServiceTest() {
 		$map = new RestfulService("");
		$params = array(
			'address' => '1600 Amphitheatre Parkway, Mountain View, CA',
			'sensor' => 'false'
		$xmlResponse = $map->request()->getBody();
		$node = '/GeocodeResponse/result/geometry/location/';
		$lattitude = $map->searchValue($xmlResponse, $node . 'lat');
		$longitude = $map->searchValue($xmlResponse, $node . 'lng');

              return "Lattitude: {$lattitude }, longitude: {$longitude}<br />";

Hope this helps,


Community Member, 103 Posts

12 January 2011 at 3:21am

Edited: 12/01/2011 3:21am

Thanks, martimiz!

That worked perfectly. For the sake of understanding, anyone have an idea why the getValues() wasn't working besides some of the wrong syntax i was using? (still doesnt work with correct syntax) I saw working examples on the forum (though they were not looking for values buried so deep in the xml) that used getValues()--Something about the way google formats the response maybe?