I'm writing application on WP 8.1 in c# and xaml that should return shops that are in some specific radius from owner of the phone. And as I looked through web I found something like points of interest but it only works for North America, I also found some out-of-date ways, but nothing works for now.
I tried this:
string uriToLaunch = #"bingmaps:?&lvl=13&q={nameOfShop}&where={city}"
var uri = new Uri(uriToLaunch);
Windows.System.Launcher.LaunchUriAsync(uri);
but it forces me to open new app and I would prefer putting pins on Map Control
but if there is no other way, is it possible to get a list of found places from this quote to bing maps?
I also tried connecting to google maps api as it has perfect option for this, I checked it from the browser and it worked just fine, but from the application it failes:
using (var client = new HttpClient())
{
client.BaseAddress = new Uri("https://maps.googleapis.com/");
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new
MediaTypeWithQualityHeaderValue("application/json"));
// HTTP GET
String uri = "maps/api/place/search/json?key={MyKey}&location="
+ position.Coordinate.Latitude
+ ","
+ position.Coordinate.Longitude +
"&radius=500&keyword={nameOfSho}&sensor=true";
HttpResponseMessage response = await client.GetAsync(uri);
if (response.IsSuccessStatusCode)
{
String content = await response.Content.ReadAsStringAsync();
}
}
I used key for web request, is it correct? There is no specific key for Windows Phone.
Thanks in advance for any suggestion!
Bing Maps has two REST services for getting point of interest data. The first is the NAVTEQ data sources in the Bing Spatial Data Services. These include data for North America and Europe. Here is some information on this service:
https://msdn.microsoft.com/en-us/library/hh478189.aspx
https://msdn.microsoft.com/en-us/library/gg585126.aspx
https://msdn.microsoft.com/en-us/library/hh757509.aspx
I also wrote a free ebook on creating spatial apps for Windows 8. In there is some good information on how to use this service. You can download a copy of the book here: https://rbrundritt.wordpress.com/my-book/
The other service is a legacy SOAP based web service. It includes some data in a lot more countries. You can find documentation on this here:
https://msdn.microsoft.com/en-us/library/dn448599.aspx
https://msdn.microsoft.com/en-us/library/dd221354.aspx
Related
I build a mobile App. This App is working really well on iOS simulator, Android emulator and Android real device. But When I published it on TestFlight and install on a real iOS device then this app does not work. I don't get any error. My spinner(activator indicator) is running forever and I cannot get any response from HttpResponse. I built this app with Web service. Therefore I'm using http://46.221..... url to post or get request. I thought that iOS does not support http request because of security . But if it's true then Why this app is running on simulator very well? I couldn't find any solution. Here is my part of codes:
public async Task<BSUser> ValidateUser(string userName, string password)
{
string url = Xamarin.Essentials.Preferences.Get(Constants.URL_KEY, "") + "/api/Validateuser";
HttpClient _Client = new HttpClient();
var data = new Dictionary<string, string>
{
{"userName", userName},
{"password", password}
};
string jsonData = JsonConvert.SerializeObject(data);
HttpContent content = new StringContent(jsonData, Encoding.UTF8, "application/json");
try
{
HttpResponseMessage httpResponse = await _Client.PostAsync(url, content);
if (httpResponse.IsSuccessStatusCode)
{
var responseData = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
var result = JsonConvert.DeserializeObject(responseData).ToString();
UserInfo userInfo = JsonConvert.DeserializeObject<UserInfo>(result);
BSUser value = new BSUser();
value.UserName = userInfo.userCode;
return value;
}
else
{
return null;
}
}
catch (SystemException)
{
return null;
}
}
enter image description here
I found the problem of my project. It's not related on HTTPS-HTTP or security situation. It's so absurd and illogical but it's the real problem. My app works on any iOS simulator well enough however, Minimum version of simulator is iPhone-8 in Visual Studio. But When I installed my app on real devices of iPhone-6 I got Newtonsoft.Json.JsonSerializationException error. But My HttpResponse returned 200OK and I see all values which comes from my service as a json. I think there some difference between old ve new versions of iPhones to convert Json Serialization.
It looks like you really should take advantage of HTTPS instead of HTTP. You can refer to these pages for more information:
https://www.hackingwithswift.com/example-code/system/how-to-handle-the-https-requirements-in-ios-with-app-transport-security
https://developer.apple.com/documentation/security/preventing_insecure_network_connections?language=objc
This is the problem with ATS in ios, if you want to use HTTP, you can config of it.
https://learn.microsoft.com/en-us/xamarin/ios/app-fundamentals/ats#configuring-ats-options.
Someone others meet the same problem like you:Xamarin Forms, iOS will not open links in WebView
I want to retrieve all the data that is present in my resource on the azure portal. I have found out that there is a REST API for application insights that can help in retrieving the data. What I want is to get the data and generate a grid report on my web page which displays the events related information, that is, date, type, message and all the related information. I haven't worked with REST API's before and what I want as a help is a proper guideline to use this REST API in my MVC based web project in visual studio. If anyone can help will be a great assistance.
You can follow the steps below:
step 1: Get the Application ID and an API key.
Nav to your application insights -> API Access, see the screenshot(Please remember, when the api key is generated, write it down):
step 2: Understand the API Format, for details, refer to here:
Here is an example for get requests count in the last 6 hours:
https://api.applicationinsights.io/v1/apps/your-application-id/metrics/requests/count?timespan=PT6H
This part https://api.applicationinsights.io/v1/apps/ do not need to change.
Then input your-application-id which you get from last step.
Then you can specify metrics or events as per your demand.
This part requests/count, you can refer to this, screenshot below:
The last part ?timespan=PT6H, you can refer to this, screenshot below:
step 3: Write your code to call this api, like below:
public class Test
{
private const string URL_requests = "https://api.applicationinsights.io/v1/apps/your-application-id/metrics/requests/count?timespan=PT6H";
public string GetRequestsCount()
{
// in step 1, you get this api key
string apikey = "flk2bqn1ydur57p7pa74yc3aazhbzf52xbyxthef";
HttpClient client = new HttpClient();
client.DefaultRequestHeaders.Accept.Add(
new MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Add("x-api-key", apikey);
var req = string.Format(URL_requests);
HttpResponseMessage response = client.GetAsync(req).Result;
if (response.IsSuccessStatusCode)
{
// you can get the request count here
return response.Content.ReadAsStringAsync().Result;
}
else
{
return response.ReasonPhrase;
}
}
}
I was trying this tutorial in Xamarin:
Performing OCR for iOS, Android, and Windows with Microsoft Cognitive Services
But I get an: Exception of type 'Microsoft.ProjectOxford.Vision.ClientException' was thrown.'
It happens in the line:text = await client.RecognizeTextAsync(photoStream);
I have looked at other post (none Xamarin) and they solved by setting the position of the stream to 0. I tried it but still get the same error.
The tutorial was written by Pierce Boggan.
Thanks for any help.
OcrResults text;
var client = new VisionServiceClient("my api key");
using (var photoStream = photo.GetStream())
text = await client.RecognizeTextAsync(photoStream);
It happens in the line:text = await client.RecognizeTextAsync(photoStream); I have looked at other post (none Xamarin) and they solved by setting the position of the stream to 0. I tried it but still get the same error.
Different Areas have different Rest API Url, So in most cases, you need to set your apiRoot manually, which wasn't mentioned the tutorial, you posted. For detailed description, you can refer to Obtain Subscription Keyps.
To do that, you can obtain the API url in your subscription page:
And use the url to construct VisionServiceClient object:
OcrResults text;
var client=new VisionServiceClient("Your API Key", "https://westcentralus.api.cognitive.microsoft.com/vision/v1.0");
using (var stream = photo.GetStream())
...
I found one interesting feature in UWP and HttpClient (it also works with WebRequest) :
Any Http request sends "If-*" headers. I did experiment with UWP and WPF apps. I sent request to Azure file storage which doesn't support "If-" headers and will return Error 400 if headers will be sended. So here is my code:
HttpClient client = new HttpClient();
var response = await client.GetAsync("LINK_TO_AZURE_FILE_STORAGE_IMAGE");
Very simply, similar for two apps. Result - WPF app doesn't send "If-*" headers, UWP does. So It means that I'm not able to use File Storage in UWP apps, I just have Error 400.
My question is - can I disable this st...d caching ? Thanks for your attention
Yeah, while using HttpClient in UWP apps, it will automatically use the local HTTP cache by default. For the first time, you code should work. Then you will get 400 Error as in the first response, it contains cache data and all subsequent requests will use this cache by default like following:
To fix this issue, we can use Windows.Web.Http.HttpClient class with HttpBaseProtocolFilter class and HttpCacheControl class to disable the cache like following:
var filter = new Windows.Web.Http.Filters.HttpBaseProtocolFilter();
filter.CacheControl.ReadBehavior = Windows.Web.Http.Filters.HttpCacheReadBehavior.MostRecent;
filter.CacheControl.WriteBehavior = Windows.Web.Http.Filters.HttpCacheWriteBehavior.NoCache;
var httpClient = new Windows.Web.Http.HttpClient(filter);
var response = await httpClient.GetAsync(new Uri("LINK_TO_AZURE_FILE_STORAGE_IMAGE"));
To make this method work, we need make sure there is no local HTTP cache. As HttpCacheReadBehavior.MostRecent represents it will still use the local HTTP cache if possible. So we'd better uninstall the app first and do not use HttpClient client = new HttpClient(); in the app.
Update:
Starting from Windows Anniversary Update SDK, there is a new enum value NoCache added to HttpCacheReadBehavior enumeration. With a combination of ReadBehavior and WriteBehavior, we can implement a variety of cache-related behaviors. When we don't want to use local cache, we can just set the ReadBehavior to HttpCacheReadBehavior.NoCache like:
var filter = new Windows.Web.Http.Filters.HttpBaseProtocolFilter();
filter.CacheControl.ReadBehavior = Windows.Web.Http.Filters.HttpCacheReadBehavior.NoCache;
var httpClient = new Windows.Web.Http.HttpClient(filter);
Have you tried using the Remove method of the DefaultRequestHeaders property of the HttpClient class?
I want to call an API called Cloud Sight that provides image recognition.
I want to get a response that basically describes the image from a URL of an image provided from the API Cloud Sight.
This is the code that I Have thus far
var client = new RestClient ("http://api.cloudsightapi.com/image_request");
var request = new RestRequest("http://cdn.head-fi.org/c/c8/1000x500px-c8c39533_beats-by-dre-studio.jpg", Method.POST);
request.AddHeader ("CloudSight", [API KEY HERE]);
IRestResponse response = client.Execute(request);
var content = response.Content;
Console.WriteLine (content);
I get an error that says
{"status":"404","error":"Not Found"}
The documentation for Cloud Sight is not very insightful for each individual language, so I am unsure if I am calling it correctly, particularly, the AddHeader part.
It may also be an error with not waiting for a response. My code executes immediately and the API example that Cloud Sight provides on their website takes 10-15 seconds.
Any ideas for how to go about getting this API working with RestSharp?
Just a guess, but have you tried Method.GET instead of Method.POST? It'd be highly unusual to fetch an image via a POST.