Skip to content

Commit

Permalink
Added reverse encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
gabber12 committed Mar 13, 2017
1 parent e5ed776 commit 1ed3625
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
8 changes: 8 additions & 0 deletions src/GeoCoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public function __construct($key)
}
const MMI_BASE = "http://apis.mapmyindia.com/advancedmaps/v1/";
const GEOCODE_API = "/geo_code";
const REVERSE_GEOCODE_API = "/rev_geocode";

public static function getUrl($api, $key)
{
Expand All @@ -26,4 +27,11 @@ public function geoCode(string $address)
$geoCodeResponse = $this->get(self::getUrl(self::GEOCODE_API, $this->key), $data);
return $geoCodeResponse;
}

public function rgeoCode(string $lat, string $lng)
{
$data = ['lat' => $lat, 'lng' => $lng];
$rgeoCodeResponse = $this->get(self::getUrl(self::REVERSE_GEOCODE_API, $this->key), $data);
return $rgeoCodeResponse;
}
}
5 changes: 5 additions & 0 deletions src/MMIResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ public function getResults() : array
return $this->results;
}

public function getVersion() : string
{
return $this->version;
}

public function isSuccess() : boolean
{
return $this->responseCode === 200;
Expand Down
19 changes: 16 additions & 3 deletions tests/TestClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@

class TestClient extends TestCase
{
protected $geoCoder;

public function setUp()
{
$this->geoCode = new GeoCoder("2vktgjh45o1nc3qxt7atmpblt3s86r7k");
}

public function testClientInstantiation()
{
$client = new Client();
Expand All @@ -23,10 +30,16 @@ public function testGeoCoderWrongLicenseKey()
}
public function testGeoCoderSuccess()
{
$geoCode = new GeoCoder("2vktgjh45o1nc3qxt7atmpblt3s86r7k");
$res = $geoCode->geoCode("saket");
$res = $this->geoCode->geoCode("saket");
$this->assertNotEmpty($res->getResults());
$this->assertNotEmpty($res->getVersion());
}


public function testRevGeoCoderSuccess()
{

$res = $this->geoCode->rgeoCode("26.5645", "85.9914");
$this->assertNotEmpty($res->getResults());
$this->assertNotEmpty($res->getVersion());
}
}

0 comments on commit 1ed3625

Please sign in to comment.