public string GetCurrentTown(double latitude, double longitude) { var gc = new Geocoder("56b83564d8cf4d7b8c3b9fe148677ab8"); var resp = gc.ReverseGeocode(latitude, longitude); return(resp.Results[0].Components.City); }
/// <summary> /// Main entry point. /// </summary> /// <param name="args">Arguments of the program.</param> static void Main(string[] args) { // Create new Geocoder and pass GOOGLE_MAPS_API_KEY(in this example it's stored in .config) IGeocoder geocoder = new Geocoder(ConfigurationManager.AppSettings["GOOGLE_MAPS_API_KEY"]); // Get GeocodeResponse C# object from address or from Latitude Longitude(reverse geocoding) GeocodeResponse response = geocoder.Geocode("1984 west armitage ave chicago il"); GeocodeResponse reversGeocoderesponse = geocoder.ReverseGeocode(40.714224, -73.961452); // You can then query the response to get what you need double latitude = response.Results[0].Geometry.Location.Lat; string address = reversGeocoderesponse.Results[1].FormattedAddress; // ..or you can get a response in JSON, XML string foramt(for whatever reason) and "play" with it string responseJson = geocoder.Geocode("1984 west armitage ave chicago il", ResponseFormat.JSON); string reverseResponseXml = geocoder.ReverseGeocode(40.714224, -73.961452, ResponseFormat.XML); // Then you can deserialize it to C# object again GeocodeResponse geocodeFromJson = geocoder.FromJson(responseJson); GeocodeResponse reverseGeocodeFromXml = geocoder.FromXml(reverseResponseXml); }
public static void Main(string[] args) { var gc = new Geocoder("924d139f8c45a512fd0fe1cfc6eb741f"); var result = gc.Geocode("newcastle", country: "GBR"); result.PrintDump(); var reserveresult = gc.ReverseGeocode(51.4277844, -0.3336517); reserveresult.PrintDump(); Console.WriteLine("Press any key to exit"); Console.ReadLine(); }
private static void Main(string[] args) { var geocoder = new Geocoder(); var start = DateTime.UtcNow; var i = 0; while (i < 10000) { var result = geocoder.ReverseGeocode(-122.4194155M, 37.7749295M); i++; } var end = DateTime.UtcNow; Console.WriteLine(start.Subtract(end).TotalSeconds); }
public static void Main(string[] args) { var gc = new Geocoder("YOURKEYHERE"); // simplest example with no optional parameters var result = gc.Geocode("newcastle"); result.PrintDump(); // example with lots of optional parameters var result2 = gc.Geocode("newcastle", countrycode: "gb", limit: 2, minConfidence: 6, language: "en", abbrv: true, noAnnotations: true, noRecord: true, addRequest: true); result2.PrintDump(); var reserveresult = gc.ReverseGeocode(51.4277844, -0.3336517); reserveresult.PrintDump(); Console.WriteLine("Press any key to exit"); Console.ReadLine(); }
public IHttpActionResult PostAlert(Alert alert) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } // Create new Geocoder and pass GOOGLE_MAPS_API_KEY(in this example it's stored in .config) IGeocoder geocoder = new Geocoder("AIzaSyCyrwDBZYm83nLY6Eg8_ECHRCF-aNQ91eQ"); // Get GeocodeResponse C# object from address or from Latitude Longitude(reverse geocoding) GeocodeResponse reversGeocoderesponse = geocoder.ReverseGeocode(alert.Latitude, alert.Longitude); // You can then query the response to get what you need string address = reversGeocoderesponse.Results[1].FormattedAddress; alert.Address = address; db.Alerts.Add(alert); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = alert.Id }, alert)); }
private bool SendToInspectorApp() { FirebaseResponse response; string path1 = "Taxis"; string path2 = "Points"; //tim taxi de gui //random 1 so tu 0 -> 99 // Taxi selectedTaxi = null; string selectedTaxiKey = null; Dictionary <string, Taxi> taxis = new Dictionary <string, Taxi>(); response = client.Get(path1); taxis = response.ResultAs <Dictionary <string, Taxi> >(); if (taxis.Count == 0) { MessageBox.Show("load taxis failed, null"); return(false); } else { foreach (var taxi in taxis) { Taxi tx = taxi.Value; string txkey = taxi.Key; if (tx.status == 0) { selectedTaxiKey = txkey; selectedTaxi = tx; MessageBox.Show("taxis have " + taxis.Count + ". this is " + tx.driverName + " with key = " + txkey); break; } } // return true; } //lay locaters cua locatedApp string addressString = ""; Geocoder geocoder = new Geocoder("AIzaSyD8aZnYa2rBuQaA_asqmH65T5FbqMq2Pyc"); if (selectedTaxi != null) { addressString = geocoder.ReverseGeocode(new LatLng(selectedTaxi.lat, selectedTaxi.lng)); } else { MessageBox.Show("Taxi is null"); return(false); } if (addressString == "") { MessageBox.Show("geocoder dia chi that bai"); return(false); } Point p = new Point(locationCb.Text.Split('(')[0], addressString, selectedTaxi.driverName, 2); //******* response = client.Push(path2, p); //them Point vao database ,(khong qua app 2) //******* object rs = response.ResultAs <object>(); if (rs == null) { return(false); } JObject o = JObject.Parse(rs.ToString()); string pointKey = (string)o.SelectToken("name");//lay pointKey selectedTaxi.cusPhonenumber = phonenumberText.Text; selectedTaxi.pointKey = pointKey; selectedTaxi.status = 3; //dang cho phan hoi if (originRBtn.Checked) { selectedTaxi.type = "origin"; } else { selectedTaxi.type = "premium"; } string path3 = "Taxis/" + selectedTaxiKey; response = client.Update(path3, selectedTaxi); //MessageBox.Show(rs.ToString() + "\n" +key); //MessageBox.Show(addressString); return(true); }