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

  • Home
  • SEARCH
  • 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 8189105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T03:09:40+00:00 2026-06-07T03:09:40+00:00

how to parse JSON google maps JSON in php i have do it in

  • 0

how to parse JSON google maps JSON in php

i have do it in xml, but the coordinates driving direction’s not complete as i get with JSON, how we can get all coordinate driving with JSON in php?

if we do using xml

$xml = simplexml_load_file('http://maps.googleapis.com/maps/api/directions/xml?origin='.$origin.'&destination='.$dest.'&sensor=false');
$startlat = $xml->xpath("/DirectionsResponse/route/leg/step/start_location/lat");
$startlng = $xml->xpath("/DirectionsResponse/route/leg/step/start_location/lng");
$distanceeach = $xml->xpath("/DirectionsResponse/route/leg/step/distance/value");
$distance = $xml->xpath("/DirectionsResponse/route/leg/distance/value");

but how to do with json?
and i want my variable $startlat, $startlng, etc, contains same value if we do with xml

  • 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-06-07T03:09:41+00:00Added an answer on June 7, 2026 at 3:09 am

    You can retrieve data in JSON format, and then use json_decode() function to build stdClass object, then you can recursively walk through object’s property to convert it into (array) $response as this.

    And then use Google Maps API response as an array. You can proceed with no converting to array, and use object of stdClass like this:

    $response->DirectionsResponse->route->leg->step->start_location->lat;
    

    To get the correct values you can always var_dump() you response object, and see what you want to get.

    Hope, that helps.


    Here is the code for usage Google JSON response from Google Translate API… which is much the same, as you need:

    if (!is_null($json = json_decode(file_get_contents($url)))
    {
        return $json->data->translations[0]->translatedText;
    }
    

    That’s it…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to parse json data from google directions but can't seem to access
Possible Duplicate: How can I parse JSON in Google App Engine? json module was
Can not parse json using this var res = eval('(' + response + ')');
I would like parse data from google maps geocode version 3 through json. I
I'm trying to parse the json response from the Google Geocode API but I'm
I have a PHP script that attempts to read and parse JSON strings returned
Parsing Google Plus JSON objects Using C# and Newtonsoft.Json library how one can parse
When I parse JSON fields coming from google maps, etc., it is a mess.
<?php include_once 'forecastVo.php'; include_once 'BaseVo.php'; $count=0; $json_url = file_get_contents( 'http://maps.google.com/maps/api/geocode/json' . '?address='jaipur'&sensor=false'); //line 9
Possible Duplicate: How to parse JSON in JavaScript I have this JSON string: [{title:

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.