Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6760899
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:07:11+00:00 2026-05-26T14:07:11+00:00

I have a question. I have the xml http://maps.googleapis.com/maps/api/geocode/xml?address=new+york&sensor=true I want to read from

  • 0

I have a question.

I have the xml

http://maps.googleapis.com/maps/api/geocode/xml?address=new+york&sensor=true

I want to read from example

GeocodeResponse/result/geometry/location/lat

and

GeocodeResponse/result/geometry/location/lng

maybe using XPATH and this is what i have so far …

<?php

$Address = "new+york";
$Query = "http://maps.googleapis.com/maps/api/geocode/xml?address=".$Address."&sensor=true";
$XmlResponse = file_get_contents($Query);

$doc = new DOMDocument();
$doc->loadXML($XmlResponse);

$root = $doc->getElementsByTagName( "GeocodeResponse" );
foreach( $root as $val )
{
    $hrefs = $val->getElementsByTagName( "status" );
    $status = $hrefs->item(0)->nodeValue;

    foreach( $hrefs as $val2 )
    {
        $hrefs2 = $val2->getElementsByTagName( "type" );
        $type = $hrefs2->item(0)->nodeValue;

        echo "Type is: $type  <br>";
    }

    echo "Status is: $status  <br>";
}


?>

Can i have some advices?

maybe i can use

$xpath = new DOMXPath($xml);
$hrefs = $xpath->evaluate("/page");

UPDATE!!

I have managed to get the result by this …

$xpath = new DOMXPath($doc);
$res = $xpath->evaluate('//GeocodeResponse/result/geometry');

$root = $doc->getElementsByTagName( "location" );
foreach( $root as $val )
{
    $hrefs = $val->getElementsByTagName( "lat" );
    $status = $hrefs->item(0)->nodeValue;

    echo "Status is: $status  <br>";
}

but i want something without foreach like

$xpath = new DOMXPath($doc);
$res = $xpath->evaluate('//GeocodeResponse/result/geometry');
$hrefs = $val->getElementsByTagName( "lat" );
$status = $hrefs->item(0)->nodeValue;

echo "Status is: $status  <br>";

Is this possible?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T14:07:12+00:00Added an answer on May 26, 2026 at 2:07 pm

    You may want to switch to JSON that is much easier to parse:

    http://maps.googleapis.com/maps/api/geocode/json?address=new+york&sensor=true

    $json = file_get_contents('http://maps.googleapis.com/maps/api/geocode/json?address=new+york&sensor=true');
    
    $geocodeResponse = json_decode($json, true);
    
    foreach($geocodeResponse['results'] as $result){
       echo $result['geometry']['location']['lat'].', '.$result['geometry']['location']['lng'] .'<br>';
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

On one fragment I have layout like question.xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > <TextView
I have a question about the use off the http api from the company
I have a quick question in reference to changing an RSS url http://www.bellyscarf.com/rsscategoryproducts.sc?categoryId=6 As
I have this build.xml file http://gist.github.com/315109 . Every task runs smoothly, but test .
I have one question/problem I have some xml. Example: api.mysite.net/xml/user/id/1145 now, i would like
For my question (below), this is my current layout: <?xml version=1.0 encoding=utf-8?> <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android
I've just started learning XML & XSLT and have a quick question regarding Xpath.
So, i have some question about xml Documents in Java. Can i get all
I have a question in parsing XML. How can I parse out the value
i have another question on getting my XML serialization neat, which i can't seem

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.