Jump to content

Message -- Warning: file_get_contents --


Go to solution Solved by Barand,

Recommended Posts

I am getting the Warning and not sure what my problem is. As you can see I am getting address data from a SQL Server and then trying to get the "lat" and "lng" information using a Google API and put that in an array that  I can use later to create a google road map. I will have about 200 locations in the array but it errors out on the first one. I have tried a different address but get the same error.Below is my data from the   echo $url ."<br>"; Thank You.

 

{ "results" : [ { "address_components" : [ { "long_name" : "1401", "short_name" : "1401", "types" : [ "subpremise" ] }, { "long_name" : "1000", "short_name" : "1000", "types" : [ "street_number" ] }, { "long_name" : "Rivergate Parkway", "short_name" : "Rivergate Pkwy", "types" : [ "route" ] }, { "long_name" : "Goodlettsville", "short_name" : "Goodlettsville", "types" : [ "locality", "political" ] }, { "long_name" : "Davidson County", "short_name" : "Davidson County", "types" : [ "administrative_area_level_2", "political" ] }, { "long_name" : "Tennessee", "short_name" : "TN", "types" : [ "administrative_area_level_1", "political" ] }, { "long_name" : "United States", "short_name" : "US", "types" : [ "country", "political" ] }, { "long_name" : "37072", "short_name" : "37072", "types" : [ "postal_code" ] } ], "formatted_address" : "1000 Rivergate Pkwy #1401, Goodlettsville, TN 37072, USA", "geometry" : { "location" : { "lat" : 36.302848, "lng" : -86.69994199999999 }, "location_type" : "ROOFTOP", "viewport" : { "northeast" : { "lat" : 36.30419698029149, "lng" : -86.69859301970848 }, "southwest" : { "lat" : 36.30149901970849, "lng" : -86.70129098029149 } } }, "place_id" : "EjgxMDAwIFJpdmVyZ2F0ZSBQa3d5ICMxNDAxLCBHb29kbGV0dHN2aWxsZSwgVE4gMzcwNzIsIFVTQQ", "types" : [ "subpremise" ] } ], "status" : "OK" } 

 

 

and this is what I get from the warning.

 

Warning: file_get_contents({ "results" : [ { "address_components" : [ { "long_name" : "1401", "short_name" : "1401", "types" : [ "subpremise" ] }, { "long_name" : "1000", "short_name" : "1000", "types" : [ "street_number" ] }, { "long_name" : "Rivergate Parkway", "short_name" : "Rivergate Pkwy", "types" : [ "route" ] }, { "long_name" : "Goodlettsville", "short_name" : "Goodlettsville", "types" : [ "locality", "political" ] }, { "long in /var/www/html/chartjs/phpgeo.php on line 44

 

 

 

<?php

ini_set('display_errors', 1);
error_reporting(E_ALL);

$connect =odbc_connect("removed");
if(!$connect) {
exit("Connection Failed: " . $connect);
}
$gr_total = 0;
$sql="
select distinct
ltrim(rtrim(cmoAddressLine2)) as Street
,ltrim(rtrim(cmoCity)) as City
,ltrim(rtrim(cmoState)) as State
 ,RIGHT( '00000' + LTRIM( RTRIM( [cmoPostCode] ) ), 5 ) as ZipCode

 from m1_kf.dbo.SalesOrders
left join m1_kf.dbo.Organizations on cmoOrganizationID=ompCustomerOrganizationID

 where ompRequestedShipDate >'11-01-17' and ompClosed !=-1

" ;
$result =odbc_exec($connect,$sql);
if(!$result){
exit("Error in SQL");
}
$json =array();
//****************************************************************
 while ($row = odbc_fetch_array($result))
{
$text = $row;
$address  = implode(", ", $text);
//echo $address ."<br>";

   $url = file_get_contents('https://maps.googleapis.com/maps/api/geocode/json?address='.urlencode($address).'&key=removed');
  echo $url ."<br>";


    $resp = file_get_contents($url);


        $lati = $resp['results'][0]['geometry']['location']['lat'];
        $longi = $resp['results'][0]['geometry']['location']['lng'];
        $formatted_address = $resp['results'][0]['formatted_address'];
        if($lati && $longi && $formatted_address){
            $data_arr = array();
            array_push(
                $data_arr,
                    $lati,
                    $longi,
                    $formatted_address
                );


            return $data_arr;
            echo $data_arr ."<br>";
        }else{
            return false;
        }
    }

odbc_close($connect);

?>
 
Link to comment
https://forums.phpfreaks.com/topic/305805-message-warning-file_get_contents/
Share on other sites

  • Solution

$url = file_get_contents('https://maps.gopis.com/maps/api/geocode/json?address='.urlencode($address).'&key=removed');

 

$resp = file_get_contents($url);

You really don't see a problem?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.