您好,我需要从 Google Geocode 打印 long 和 lat 值。我已经使用以下方法检索了 xml:
$url ="http://maps.googleapis.com/maps/api/geocode/xml?address=se18lu&sensor=false";
$result = simplexml_load_file($url);
它返回以下内容:
SimpleXMLElement Object
(
[status] => OK
[result] => SimpleXMLElement Object
(
[type] => postal_code
[formatted_address] => Bankside, London Borough of Lambeth, London SE1 8LU, UK
[address_component] => Array
(
[0] => SimpleXMLElement Object
(
[long_name] => SE1 8LU
[short_name] => SE1 8LU
[type] => postal_code
)
[1] => SimpleXMLElement Object
(
[long_name] => Bankside
[short_name] => Bankside
[type] => Array
(
[0] => sublocality
[1] => political
)
)
[2] => SimpleXMLElement Object
(
[long_name] => London
[short_name] => London
[type] => Array
(
[0] => locality
[1] => political
)
)
[3] => SimpleXMLElement Object
(
[long_name] => London Borough of Lambeth
[short_name] => London Borough of Lambeth
[type] => Array
(
[0] => administrative_area_level_3
[1] => political
)
)
[4] => SimpleXMLElement Object
(
[long_name] => Greater London
[short_name] => Gt Lon
[type] => Array
(
[0] => administrative_area_level_2
[1] => political
)
)
[5] => SimpleXMLElement Object
(
[long_name] => United Kingdom
[short_name] => GB
[type] => Array
(
[0] => country
[1] => political
)
)
)
[geometry] => SimpleXMLElement Object
(
[location] => SimpleXMLElement Object
(
[lat] => 51.5034227
[lng] => -0.1080750
)
[location_type] => APPROXIMATE
[viewport] => SimpleXMLElement Object
(
[southwest] => SimpleXMLElement Object
(
[lat] => 51.5020958
[lng] => -0.1094971
)
[northeast] => SimpleXMLElement Object
(
[lat] => 51.5047938
[lng] => -0.1067991
)
)
[bounds] => SimpleXMLElement Object
(
[southwest] => SimpleXMLElement Object
(
[lat] => 51.5032242
[lng] => -0.1087301
)
[northeast] => SimpleXMLElement Object
(
[lat] => 51.5036654
[lng] => -0.1075661
)
)
)
)
)
一切都很好。我现在需要从 xml 中检索 long 和 tat 值吗?我如何只打印/显示这些值“lat”???:例如
结果->几何->位置->纬度