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 8438443
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T07:43:04+00:00 2026-06-10T07:43:04+00:00

I develop a back-end for a mobile application with cakephp I have a function

  • 0

I develop a back-end for a mobile application with cakephp

I have a function that list cities and I want to calculate distance from the user the this cities the code is:

$origins='origins=casablanca,maroc';
    $destinations='&destinations=';
    $url='http://maps.googleapis.com/maps/api/distancematrix/json?';

    $this->paginate = array(
            'limit' => 10,
            'fields'=>array('cityId','cityFileName','cityName','stateId','stateFileName','stateName',
                'countryCode','countryFileName','countryName','count(id) as num_hotels'),
            'order' => 'num_hotels desc',
            'group' =>array('cityId')

    );
    $hotels = $this->paginate();

    for ($i = 0; $i < count($hotels); ++$i) {

        $destination=($i==0?'':'|');

        $destination.=$hotels[$i]['Hotel']['cityName'].','.$hotels[$i]['Hotel']['countryName'];

        $destinations.=$destination;
    }

    $url.=$origins.$destinations.'&mode=driving&language=fr-FR&sensor=false';

    $json = file_get_contents($url,0,null,null);
    $details = json_decode($json, TRUE);

    for ($i = 0; $i < count($hotels); ++$i) {
        $hotels = Set::insert($hotels, $i.'.Hotel.distance',$details['rows']['0']['elements']['0']['distance']['value']);
    }

    $this->set(compact('hotels'));
    $this -> viewPath = "hotels";
    $this -> render("json/index","json/default");

the problem is when i test with the first page (pagination) the result is good but when i access to others page >=2 i got this warning and i cant get the distance

the error is :

Warning (2): file_get_contents(http://maps.googleapis.com/maps/api/distancematrix/json?origins=casablanca,maroc&destinations=Zagora,Morocco|Meknes,Morocco|Chefchaouen,Morocco|Tinghir,Morocco|M'hamid,Morocco|El Jadida,Morocco|Erfoud,Morocco|Skoura,Morocco|Tetouan,Morocco|Imlil,Morocco&mode=driving&language=fr-FR&sensor=false) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request

[APP\Controller\ApiController.php, line 81]

Code Context

$origins = “origins=casablanca,maroc”
$destinations = “&destinations=Zagora,Morocco|Meknes,Morocco|Chefchaouen,Morocco|Tinghir,Morocco|M’hamid,Morocco|El
Jadida,Morocco|Erfoud,Morocco|Skoura,Morocco|Tetouan,Morocco|Imlil,Morocco”
$url = “http://maps.googleapis.com/maps/api/distancematrix/json?origins=casablanca,maroc&destinations=Zagora,Morocco|Meknes,Morocco|Chefchaouen,Morocco|Tinghir,Morocco|M‘hamid,Morocco|El
Jadida,Morocco|Erfoud,Morocco|Skoura,Morocco|Tetouan,Morocco|Imlil,Morocco&mode=driving&language=fr-FR&sensor=false”
$hotels = array( array( “Hotel” => array(), array() ), array(
“Hotel” => array(), array() ), array( “Hotel” => array(), array()
), array( “Hotel” => array(), array() ), array( “Hotel” =>
array(), array() ), array( “Hotel” => array(), array() ), array(
“Hotel” => array(), array() ), array( “Hotel” => array(), array()
), array( “Hotel” => array(), array() ), array( “Hotel” =>
array(), array() ) ) $i = 10 $destination = “|Imlil,Morocco”
$http_response_header = array( “HTTP/1.0 400 Bad Request”,
“Content-Type: text/html; charset=UTF-8”, “Content-Length: 925”,
“Date: Wed, 08 Aug 2012 15:42:43 GMT”, “Server: GFE/2.0” )

file_get_contents – [internal], line ?? ApiController::yassine() –
APP\Controller\ApiController.php, line 81
ReflectionMethod::invokeArgs() – [internal], line ??
Controller::invokeAction() – CORE\Cake\Controller\Controller.php, line
473 Dispatcher::_invoke() – CORE\Cake\Routing\Dispatcher.php, line 104
Dispatcher::dispatch() – CORE\Cake\Routing\Dispatcher.php, line 86
[main] – APP\webroot\index.php, line 96

  • 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-10T07:43:06+00:00Added an answer on June 10, 2026 at 7:43 am

    You must correct this line.

    $url.="origins=" .  urlencode($origins). "&destinations=" .
          urlencode($destinations)."&mode=driving&language=fr-FR&sensor=false";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm building an HTML5 application (with ASP.NET back-end) and i want to develop it
I am trying to develop a back-end Ad Checking application in PHP. We have
I have been tasked with taking an Access 97 application and moving the back-end
We want to develop a business mobile app that would integrate with our existing
I have been develop API using asp.net with C# back-end code. i would like
I am going to develop a WCF service that connects back-end system with two
I develop on VS2010 WPF on Window 7. I have a project that does
There is one software application in which foxpro is used as back-end. Now this
Intro: I want to develop simple multiplayer Five in row (Gomoku). Front-end should be
Me and my team are developing an application, which involves a back-end written in

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.