Memo--Base station positioning Technology (reprint)

Source: Internet
Author: User
Tags curl vars

Many friends are using Google Geolocationapi interface to test base station positioning, testing needs to interface Http://www.google.com/loc/json to submit JSON format data, JSON format parameters are more, Testing in the IDE is also troublesome, sometimes because a grammatical error has to be checked for a long time.

Here Ant recommends a simpler way to test the correctness of the JSON data format: using the Curl Test.

Curl is a file transfer tool that uses URL syntax to work in a command-line manner. It is convenient to use Curl to submit HTTP Get/post data. Curl is a common tool under Unix/linux, as well as a version of Windows.

Geolocationapi's detailed syntax is not introduced here.

For example, we want to query lac:14556 by Http://www.google.com/loc/json, cellid:36525 base station location. According to the syntax mentioned in GEOLOCATIONAPI, the submitted data should be in this format:

{
"Version": "1.1.0",
"Host": "Maps.google.com",
"Access_token": "2:k7j3g6lal6u_lafw:4ixoeopth1glsxe",
"Home_mobile_country_code": 460,
"Home_mobile_network_code": 0,
"Address_language": "ZH_CN",
"Radio_type": "GSM",
"Request_address": true,
"Cell_towers": [
{
"cell_id": 36526,
"Location_area_code": 14556,
"Mobile_country_code": 460,
"Mobile_network_code": 0,
"Timing_advance": 5555
}
]
}

Let's use curl to test that the format is correct.

Command format: curl-d ' post data ' Http://www.google.com/loc/json

Here we only need to use the-D parameter of curl, followed by-D is the data content of post

At the command line, enter "Curl-d '" after the return, paste the above JSON format data entry, and then enter "' Http://www.google.com/loc/json" return, you can see the results of Google returned.

A variety of JSON parameter combinations can be easily tested by curl.

More than the interface description, I wrote the following available code

<?php
function Curl_post ($url, $vars, $second =30)
{
$ch = Curl_init ();
curl_setopt ($ch, Curlopt_timeout, $second);
curl_setopt ($ch, Curlopt_returntransfer, 1);
curl_setopt ($ch, Curlopt_url, $url);
curl_setopt ($ch, Curlopt_post, 1);
curl_setopt ($ch, Curlopt_postfields, $vars);
$data = curl_exec ($ch);
Curl_close ($ch);
return $data;
}

$vars = ' {
"Version": "1.1.0",
"Host": "Maps.google.com",
"Access_token": "2:k7j3g6lal6u_lafw:4ixoeopth1glsxe",
"Home_mobile_country_code": 460,
"Home_mobile_network_code": 0,
"Address_language": "ZH_CN",
"Radio_type": "GSM",
"Request_address": true,
"Cell_towers": [
{
"cell_id": 36526,
"Location_area_code": 14556,
"Mobile_country_code": 460,
"Mobile_network_code": 0,
"Timing_advance": 5555
}
]
}';
$rdata = Curl_post (' Http://www.google.com/loc/json ', $vars);
$r _ary = (array) json_decode ($rdata);
Print_r ($r _ary[' location ']);
?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.