How can i get the country name from latitude and longtitude using c#?
Im using the Bing.Map API
Location location12 = new Location(location.Latitude, location.Longitude);
MapLayer.SetPosition(pin, location12);
Map.Children.Add(pin);
string placeName = GetPlaceNameForCoordinates(location.Latitude, location.Longitude);
You'll want to use a reverse geocoding API of some kind. For example:
The Bing Maps API (the webservice)
The Google Geocoding API
The Geonames API
If you're already using the Bing.Maps SDK, you should use the Map.SearchManager property to get a SearchManager, and then use the ReverseGeocodeAsync method. In particular, as noted in comments, mixing and matching which API you use to show data via other SDKs may well violate the terms and conditions of both: be careful which technologies you use within a single application. (Even though this question gives sample code using the Bing Maps SDK, I've kept the list above in order to help others who may come with a slightly different context.)
For example:
var manager = map.SearchManager;
var request = new ReverseGeocodeRequestOptions(location) {
IncludeEntityTypeFlags = ReverseGeocodeEntityType.CountryRegion
};
var response = await manager.ReverseGeocodeAsync(
new ReverseGeocodeRequestOptions(location) { );
// Use the response
If you decide to use the Geonames API, the data can be downloaded for offline use too.
I've created a github project with sample code that does this without api calls
see here
Very simple country name and id returned
Related
We use the AmazonDeviceFarmClient.ListDevicesAsync call with a very simple ListDevicesRequest in order to get a list of all devices available in Device Farms in a C# platform.
An example of our code:
var cfg = new AmazonDeviceFarmConfig
{
RegionEndpoint = RegionEndpoint.USWest2
};
using (var client = new AmazonDeviceFarmClient(new BasicAWSCredentials([DeviceFarmAccessKey], [DeviceFarmSecretKey]), cfg))
{
var arn = GetProjectArn();
var response = client.ListDevicesAsync(new ListDevicesRequest
{
Arn = arn
}).Result;
}
On Powershell/python, using the aws devicefarm list-devices command, a comprehensive list of all possible devices is returned.
Using our C# code we get a truncated list, missing several devices that we need, despite there being no filters. We have tried various things including changing the permissions of the API user, and changing the region with no luck.
It looks increasingly like our best course of action will be to run a powershell script within our C# environment, rather than using the C# Device Farm API, whose list devices command appears to be not working.
Given that we are waiting for a result using the Result keyword, I would not expect this to be an async issue.
As pointed out by Jeroen Mostert, we missed out on the NextToken property. It was sending an incomplete list down (an uneven number, like 236, which made us think that it wasn't a pagination type issue), and using NextToken in a repeat call to the same method gave us the few remaining results.
Thank you for your prompt response!
Recently when working with Lex in C#, I have referenced AWSCore.dll and AWSLex.dll and still trying to get a method that exposes all available Lexchatbots that I created in the Aamazon server.
var amazonPostRequest = new Amazon.Lex.Model.PostContentRequest();
var amazonPostResponse = new Amazon.Lex.Model.PostContentResponse();
used both methods to get all other information. Methods in request for bot name and alias is for setting and there is no method in response for getting available Lexchatbots in the server.
I don't believe that the Lex SDK supports this call directly.
Use the AWS Lex REST API to get a list of bots:
GET https://<your aws region endpoint>/bots/
https://docs.aws.amazon.com/lex/latest/dg/API_GetBots.html
After a long research I found the answer to my problem, It may help others.
First we need to add the AWSSDK.LexModelBuildingService through Nuget. This will add reference to the DLL.
From that all methods already exposed. We need to create both GetBotsRequest and GetBotsResponse methods.
var botRequest = new Amazon.LexModelBuildingService.Model.GetBotsRequest();
var botResponse = new Amazon.LexModelBuildingService.Model.GetBotsResponse();
Then we need to call lex model building service client
var amazonmodel = new AmazonLexModelBuildingServiceClient("YourAccesKeyId","YourSecretAccessKey",Amazon.RegionEndpoint.USEast1);
After that we can get the response of inbuilt method of GetBots()
botResponse = amazonmodel.GetBots(botRequest);
We will get the list of bots metadata
List<Amazon.LexModelBuildingService.Model.BotMetadata> bots = botResponse.Bots;
Every details about each bot created will be available in the array of list of bots
There is almost all methods in getting details from Lex configuration in LexModelBuildingService dll
Note:
In IAM (Identity Access Management) in AWS we need to give Access to have Lex components in Policy section. AWSLexFullAccess
or
atleast arn:aws:lex:region:account-id:bot:* access in policy
I'm upgrading a C# application used at work to gather client satisfaction stats using Survey Monkey. The upgrade is to make it use the Survey Monkey API V3 instead of V2 (since V2 gets turned off soon). Both versions of our code make use of Ben Emmett's excellent .NET wrapper(https://github.com/bcemmett/SurveyMonkeyApi) extended with appropriate methods to support creating new surveys and sending invitations.
In version 2 we used the Create_Flow API method to generate new surveys based on an existing one (we have a couple of existing base surveys and choose the appropriate one based on the type of project we're surveying about). It's important that the title of the new survey reflect the name of the relevant project. The relevant part of our V2 code looks like this:
var data = new CreateFlowSettings();
data.survey.survey_title = legislationTitle;
data.survey.from_survey_id = fromSurveyId;
data.collector.recipients = recipients;
data.email_message.subject = subject;
data.email_message.body_text = bodyText;
data.email_message.reply_email = replyEmail;
var serializedData = JsonConvert.SerializeObject(data);
const string endPoint = "/batch/create_flow";
var response = MakeApiRequest(endPoint, serializedData);
var createFlowResponse =
JsonConvert.DeserializeObject<CreateFlowResponseObjects.CreateFlowResponse>(response.ToString());
return createFlowResponse;
In V3 we create our surveys using the /surveys endpoint like so (the term 'template' used in the code below is not a reference to the Survey Monkey concept of template surveys):
public Survey CreateSurvey(string templateSurveyid, string newSurveyTitle)
{
const string endpoint = "/surveys";
var requestData = new RequestData {{"from_survey_id", templateSurveyid}, {"title", newSurveyTitle}};
var result = MakeApiRequest(endpoint, Verb.POST, requestData);
return result.ToObject<Survey>();
}
In V2 the title of the survey displayed at the top of each page in our new surveys would reflect the 'survey_title' data we sent with the API request. In V3 however the 'title' value is NOT replacing the text appearing at the top of each page. It IS correctly determining the name of the survey on the site but at the top of each page we see the title of the survey on which the new one was based (the survey with the id passed to the API as 'from_survey_id').
I think I've googled this pretty extensively and can't find anybody else describing this problem. Any ideas what I am doing wrong? Do I need to code modifying the survey after creation to achieve this in V3?
So it turns out this is a bug in API v3. Only part of the survey title is being updated on copy survey.
This has been resolved - expect a fix out (likely sometime this week) and it will start working without any changes on your side.
Note: PATCH on the survey should be working properly (but I wouldn't recommend coding around the issue unless necessary)
I have set up a basic C# application to run a PageSpeed test on a website that I specify using the Google.Apis.Pagespeedonline.v2 nuget package.
The set up is simple enough and I have a variable that I can specify the url which is then past in to the Service
// Create the service.
var service = new PagespeedonlineService(new BaseClientService.Initializer
{
ApplicationName = "PageSpeed Sample",
ApiKey = "[API_KEY_HERE]"
});
var url = "URL_TO_TEST";
// Run the request.
var result = await service.Pagespeedapi.Runpagespeed(url).ExecuteAsync();
The problem being the .Runpagespeed method ONLY accepts URL. I need to be able to specify, at minimum, the 'Mobile' strategy so I can obtain scores for both Desktop and Mobile. I know this is possible in other libraries but seems to be missing in .NET. Is anybody aware of a way to do this using the .NET library? In the reference documentation it implies that the method accepts further optional parameters but it does not in the code.
Pagespeedapi: runpagespeed has an optional value called strategy
strategy string The analysis strategy to use
Acceptable values are: "desktop": Fetch and analyze the URL for
desktop browsers "mobile": Fetch and analyze the URL for mobile
devices
Example:
var request = service.Pagespeedapi.Runpagespeed(url);
request.Strategy = Google.Apis.Pagespeedonline.v2.PagespeedapiResource.RunpagespeedRequest.StrategyEnum.Mobile;
var results = request.Execute();
i build mini Question Answering System in C#. I need retrieve document by google Search.
What is google tools name, i can use it in my project?
Thanks
One possibility is to set up a custom Google search engine. Then you also need to create a developer key, which I believe is done under the console.
After setting that up, you can make REST style call with code such as the following, which retrieves the results as JSON:
WebClient w = new WebClient();
string result;
string uri;
string googleAPIKey = "your developer key";
string googleEngineID = "your search engine id";
string template = "https://www.googleapis.com/customsearch/v1?key={0}&cx={1}&q={2}&start={3}&alt=json";
int startIndex = 1;
int gathered = 0;
uri = String.Format(template, googleAPIKey, googleEngineID, "yoursearchstring", startIndex);
result = w.DownloadString(uri);
For extracting the information from the JSON results, you can use something like Json.NET. It makes it extremely easy to read the information:
JObject o = JObject.Parse(result);
Then you can directly access the desired information with a single line of code.
One important piece of information is that the search API free usage is extremely limited (100 requests per day). So for a real-world application it would probably be necessary to pay for the search. But depending on how you use it, maybe 100 requests per day is sufficient. I wrote a little mashup using the Google search API to search for Stackoverflow site information of interest and then used the StackExchange API to retrieve the information. For that personal use, it works very well.
I've never used it before (and it's alpha), but take a look at Google APIs for .NET Framework library.