Traccar server url1/1/2023 Var mapResponse = (ser.ReadObject(es) as Response) //Response is one of the Bing Maps DataContracts Using (var es = new MemoryStream((response))) We can do this using DataContractJsonSerializer and a MemoryStream: string response = client.DownloadString(url) ĭataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(Response)) Now, the response will be JSON, so we must find some way to translate that into the contracts we acquired from Bing earlier. String response = client.DownloadString(url) OK great, now we've got the URL we need to hit to get results, but what do we use to actually make that request? We use a class called WebClient and a method called DownloadString: string url = "" + address + "&key=BingMapsKey" String url = "" + address + "&key=BingMapsKey" Public static LatLong Geocode(string address) Here's how we set that up: public class LatLong In order to make the call to the API, we'd insert this address into the URL format from above, so that our request would look like this: W Washington St Phoenix, AZ 85007&key=BingMapsKeyīut how do we do that in code? We want to accept an address and return a latitude and longitude. Let's build some examples! Geocoding an Addressįirst, let's imagine that we get an address that looks like this: Now, we've got three pieces: the location of the service, the key necessary to call the service, and the contracts necessary to read data returned by the service. But what objects would the system deserialize to? Turns out, Microsoft has already provided the data contracts necessary for deserializing Bing Maps API data all we have to do is copy those contracts to our local project. Which means that our system will need to be able to read and deserialize JSON objects. Whenever we make a request to this service, we will receive back a JSON response (though this is configurable). The basic format for that URL looks like this (I have omitted some of the query string options for brevity): For this demo, we will use the Query service call using an unstructured URL. Second, we need to know where the Bing Maps REST services exist. #Traccar server url codeIf you want to use the code in this demo, be sure to supply your own, valid Bing Maps key. This post is mostly written so I'll be able to find it again, but hopefully some of you intrepid readers out there will get use out of it too.įirst of all, in order to even call the Bing Maps REST services you'll need a Bing Maps Key. NET server-side application and never using Bing Maps REST services, which is a requirement for this application. I've dealt with geocoding before, but never in a. #Traccar server url licenseWinkel triple projection by Strebe, used under license This means that, given a valid address, we should have the ability to find that address latitude and longitude coordinates so that we can store those values in our database.
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |