PHP code example of graychen / geolocation

1. Go to this page and download the library: Download graychen/geolocation library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

graychen / geolocation example snippets

 php

namespace graychen\Tests;

use PHPUnit\Framework\TestCase;
use graychen\geolocation\BaiduGeolocation;

class BaiduGeolocationTest extends TestCase
{
    private $geolocation;

    public function setUp()
    {
        $this->geolocation=new BaiduGeolocation();
    }

    /**
     * Asserts that the container can set and get a simple closure with args.
     */
    public function testGetgeolocation()
    {
        $this->geolocation->latitude= "your latitude";
        $this->geolocation->longitude= "your longitude";
        $this->geolocation->ak= "your ak";
        $json_content=$this->geolocation->getGeolocation();
        $province=$json_content["result"]["addressComponent"]["province"];
        $this->assertEquals("江苏省", $province);
    }
}