Reputation: 103
I am trying to get lat-long from cellid and LAC.
I have been trying to use this script mentioned in Trouble with Sending JSON object over POST to Google Gears to accomplish this
Can you please point out any error if any or any alternate way?
I am pasting the code below
<?php
$urlstring="http://www.google.com/loc/json";
$ch=curl_init($urlstring);
$cell_towers = array();
$row=new stdClass();
$row->location_area_code=3311;
$row->mobile_network_code=71;
$row->cell_id=32751;
$row->mobile_country_code=404;
$cell_towers[]=$row;
$param = array(
'host'=> 'localhost',
'version' => '1.1.0',
'request_address' => true,
'cell_towers' => $cell_towers
);
$param_json=json_encode($param);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch,CURLOPT_POSTFIELDS,$param_json);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("application/json"));
$result=curl_exec($ch);
echo $result;
?>
This is the code after making the change(of removing url_encode)
Upvotes: 0
Views: 2207
Reputation: 75
Yes, your code is identical to mine, the only line where it differs is:
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
This bit of code uses CURL. Have you enabled the CURL library? It is disabled by default in most PHP installations.
Upvotes: 0