Jump to content


Photo

file_get_contents failed to open stream


  • Please log in to reply
3 replies to this topic

#1 unemployment

unemployment

    Advanced Member

  • Members
  • PipPipPip
  • 746 posts

Posted 09 January 2012 - 03:10 PM

I am trying to use the google maps to geocode a location but I get this error:

Warning: file_get_contents(http://maps.google.c...son?address=New London,+Connecticut,+United States&sensor=false): failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request

$location_request 	= "http://maps.google.com/maps/api/geocode/json?address={$city},+{$real_state},+{$real_country}&sensor=false";
$geocode 	        = file_get_contents($location_request);

What am I doing wrong?  I tried URL encoding the location request but that also didn't work.


#2 Muddy_Funster

Muddy_Funster

    Advanced Member

  • Members
  • PipPipPip
  • 3,271 posts

Posted 09 January 2012 - 03:15 PM

it should work if you wrap your strings thus:
$location_request 	= "http://maps.google.com/maps/api/geocode/json?address='$city',+'$real_state',+'$real_country'&sensor=false";

Please: "This doesn't work..." is not a question.  We're not the government: we don't have anything to view what your doing on your computer.  Help us help you by asking a good question.

 

"Things needed to ask a "good" question:

  • A description of the context of your issue (Optional but can be a huge help in certain circumstances)
  • What is the actual problem (Mandatory)
  • What does the code actually do (Mandatory)
  • What you think the code should do / What you want the code to do (Mandatory)
  • What things have you tried so far (Optional, but missing it out just wastes your time and ours)
  • The actual code as you are running it - minus any personal information like Database Login Credentials (Mandatory - don't just post pseudo, the vast majority of issues are syntax and not logic)
  • As much info about your development environment as you can give - even if it's just letting us know you are using a hosting provider instead of a local install (Optional, but some questions can not be answered without it.)

 

 

My SQL/PHP Blog


#3 unemployment

unemployment

    Advanced Member

  • Members
  • PipPipPip
  • 746 posts

Posted 09 January 2012 - 03:52 PM

it should work if you wrap your strings thus:

$location_request 	= "http://maps.google.com/maps/api/geocode/json?address='$city',+'$real_state',+'$real_country'&sensor=false";


It's still not working.  I get the same error.  Any other thoughts?

#4 unemployment

unemployment

    Advanced Member

  • Members
  • PipPipPip
  • 746 posts

Posted 09 January 2012 - 04:06 PM

got it.  I had to urlencode only the variables.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users