Original API description available here: http://api.2gis.ru/doc/main/

Here is a brief tutorial.

You need to add GisApiWrapper.dll to your project. After that you will have ability to use all methods.

Constructor

using GisApiWrapper;

...

GisApi api = new GisApi("your_secret_key");

or you could use your own instance of WebClient:

using GisApiWrapper;

...
WebClient client = new WebClient();
GisApi api = new GisApi("your_secret_key", client);

Methods

Because of some method variation wrapper has 3 methods.

FindFirms

Returns firms by "What?" and "Where?" key.

using GisApiWrapper;
using GisApiWrapper.Responses;
using GisApiWrapper.Types;
...

GisApi api = new GisApi("your_secret_key");
api.FindFirms("коньяк", "новосибирск", 1000, 1, 30, SortEnum.name, GetFirms);
First 2 parameters are always must be set for this method. Other parameters are nullable. You can write something like this:
api.FindFirms("коньяк", "новосибирск", null, null, null, null, GetFirms);
The last parameter - callback procedure. Procedure must be created inside the class where you are using the method.
//.NET WinForms Example
public void GetFirms(ApiResponse<FirmSearchResponse> response)
{
    ////Working with response
}
Note: Always check that ApiResponse type is matching the calling method. In our case, FirmSearchResponse is bind to FindFirms method.

FindFirms method can be used to find the firms near a geo-location.
api.FindFirms("вермут", new GeoPoint(55,37), 1000, 1, 30, SortDirections.Name, GetFirms);

Or method can be used to find the firms in bounds.
api.FindFirms("кафе","новосибирск", new Bound(new GeoPoint(55,37),new GeoPoint(56,35)), GetFirms);

Or find firms by rubric name.
api.FindFirms("хостинг", "новосибирск", 1000, 1, 30, SortDirections.Name, GetFirms);

GetRubrics

Returns rubrics by "Where?" key.

using GisApiWrapper;
using GisApiWrapper.Responses;
using GisApiWrapper.Types;
...

GisApi api = new GisApi("your_secret_key");
api.GetRubrics("новосибирск", GetRubrics);
or you can set a Rubric ID to get specific rubric
using GisApiWrapper;
using GisApiWrapper.Responses;
using GisApiWrapper.Types;
...

GisApi api = new GisApi("your_secret_key");
api.GetRubrics("новосибирск","123465","", GetRubrics);
Note: The 3rd parameter is parent category ID. To get only root categories leave it empty. If Rubric ID is set (2nd parameter) - the parent category ID will be ignored.

GetFirmInfo

Returns full firm information.

api.GetFirmInfo("141265770441087", "0428eade87f6540057a294b9d4e67c313245", GetProfile);

All parameters must be set.
First parameter: firm ID. Retrieved by FindFirms.
Second parameter: unique firm hash. Retrieved by FindFirms also.

Callback procedure for this method will be:
public void GetProfile(ApiResponse<FirmProfileResponse> response)
{
     ////Working with response           
}

GetFirmsBranches

Returns all braches of the firm by it's firm group ID.

api.GetFirmsBranches("141274359434662", GetFirmsBranches);

Callback procedure for this method will be:
public void GetProfile(ApiResponse<BranchesOfFirmResponse> response)
{
     ////Working with response           
}

GetProjects

Returns all projects.

api.GetProjects(GetProjects);

Callback procedure for this method will be:
public void GetProjects(ApiResponse<GetProjectResponse> response)
{
     ////Working with response           
}

GetCitiesInProject

Returns all cities in project.

api.GetCitiesInProject("Новосибирск", GetCities);

Callback procedure for this method will be:
public void GetCities(ApiResponse<GetCitiesResponse> response)
{
     ////Working with response           
}

GetGeoObjects

Returns all geo objects by query or point coordinats.

api.GetGeoObjects("Новосибирск", GetGeoObjects);

or

api.GetGeoObjects(new GeoPoint(55, 37), GetGeoObjects);

Callback procedure for this method will be:
public void GetGeoObjects(ApiResponse<GetGeoObjectResponse> response)
{
     ////Working with response           
}

RegisterProfileViews

Registers the profile views by firm hash.
Result: 1 - if registered fine, else - 0;

api.RegisterProfileViews("0428eade87f6540057a294b9d4e67c313245", Registered);

Callback procedure for this method will be:
public void Registered(ApiResponse<int> response)
{
     ////Working with response           
}

FindAds

Finds the ads by "What?" and "Where?" keys.

api.FindAds("реклама", "новосибирск", GetAds);

Last edited Feb 13, 2012 at 1:18 PM by Lans, version 9

Comments

No comments yet.