I think about stuff and then I make videos about it sometimes.
chadly / geocoding.net Goto Github PK
View Code? Open in Web Editor NEWC# GeoCoding / Address Validation API
License: MIT License
C# GeoCoding / Address Validation API
License: MIT License
I think about stuff and then I make videos about it sometimes.
See more info:
https://developers.google.com/maps/documentation/geocoding/intro#ComponentFiltering
I recommend this feature for you that is already developing in:
maximn/google-maps#67
If I call ReverseGeocodeAsync( 51.441163, 0.000081) this generates a request:
GET https://maps.googleapis.com/maps/api/geocode/xml?latlng=51.441163,8.1E-05&sensor=false HTTP/1.1
which in turn generates:
<?xml version="1.0" encoding="UTF-8"?>
<GeocodeResponse>
<status>INVALID_REQUEST</status>
<error_message>Invalid request. Invalid 'latlng' parameter.</error_message>
</GeocodeResponse>
Suggestions?
Hi,
excellent library incidentally.
A recent test I did looping through 200 records to return a set of coordinates and I am now getting an error (OverQueryLimit) indicating I need to (presumably sign in with an apikey) so google can track my queries via my gmail account. Looking at the source it appears that the APIkey logic hasn't been defined for the googleGeocode library. Is this correct?
Cheers
Tim,
One item I cannot figure out is how to obtain the request status, in my case the GoogleStatus. I don't see anyway from either the GoogleGeocoder or the GoogleAddress objects.
I then assumed that if the google api returned anything other than OK, Geocoding.net would throw a GoogleGeocodingException, but am not getting any exceptions.
Thank you for putting this together.
Hello all - is there any way to access the Accuracy value that Google returns? I've gone through the properties available through intellisense but can't find anything that looks valuable. (And sorry for raising an issue - I couldn't find a discussion forum anywhere).
In certain cases, the Google geocoding web service returns a longitude result of -180, which does not appear to be valid when parsing the results into the Location object. I have tried to eliminate the issue by providing custom bounds in the query, but it is not always consistent.
Here is an example with a longitude of -180 from the Google geocoding service:
Here is what I believe to be an issue in the code when attempting to parse the longitude in the Location class:
public virtual double Longitude
{
get { return longitude; }
set
{
if (value <= -180 || value > 180)
throw new ArgumentOutOfRangeException("Longitude", value, "Value must be between -180 and 180 (inclusive).");
if (double.IsNaN(value))
throw new ArgumentException("Longitude must be a valid number.", "Longitude");
longitude = value;
}
}
I am looking to extract only the city for a given lat/lng
As seen in this XML:
https://stackoverflow.com/a/3151512/169714
it would have an enumerable of address_component
and a type locality
which contains the city.
Would be a great addition imho.
I will try to do this soon
Newtonsoft.Json does not serialize the Resource as a Location type, thus the cast in the ParseResponse-Method fails.
This issue may be present in other Geocoders. It has appeared in a project built from source, incorporating Geocoding.Core and Geocoding.Microsoft. The target framework is .NET 4.6.1.
Calling ReverseGeoCode(double, double) results in a culture dependent string conversion. This in turn leads to incorrect or missing addresses (depending on provider). Example, using Bing on Swedish locale gives the following call
http://dev.virtualearth.net/REST/v1/Locations/47,64054,-122,12934?key=xxx
where the correct call should be
http://dev.virtualearth.net/REST/v1/Locations/47.64054,-122.12934?key=xxx
For Google this just fails and gives zero results, for Bing it gives "low resolution" results
To fix this i think it is enough to change the calls to GetResponse from
String.Format("{0},{1}", latitude, longitude)
to
string.Format(new System.Globalization.CultureInfo("en-US"), "{0},{1}", latitude, longitude)
I will try to do this soon.
Getting a GoogleGeocodingException - "Value cannot be empty. Parameter name: components"
Run the example and enter: "muswellbrook 2 New South Wales Australia"
at Geocoding.Google.GoogleGeocoder.ProcessRequest(HttpWebRequest request)
at Geocoding.Google.GoogleGeocoder.Geocode(String address)
at Geocoding.Google.GoogleGeocoder.Geocoding.IGeocoder.Geocode(String address)
at Example.Web.Controllers.HomeController.Geocode(String address)
The Google and Microsoft providers are explicitly always setting the Proxy on the web request, even if it is null
. Which makes it cumbersome to use the default system proxy. And it causes the requests to ignore it if you supply this in your .config:
<system.net> <defaultProxy enabled="true" useDefaultCredentials="true" /> </system.net>
Instead, consider:
if(this.Proxy != null) {
request.Proxy = this.Proxy;
}
The MapQuest geocoder does this. The Yahoo Geocoder doesn't seem to support proxies at all. Not only that, the property should really be changed to an IWebProxy
instead of WebProxy
. Because even if I manually wanted to set the provider to use the default proxy, System.Net.WebRequest.DefaultWebProxy
returns the interface (IWebProxy
) and not the class (WebProxy
).
I see no way to customize the timeout of HTTP call to google. Maybe i miss something, if not, i can make a PR :
var req = WebRequest.Create(url) as HttpWebRequest;
Hi,
Please could you strongly name the assemblies? Otherwise us with signed assemblies need to rebuild this and add our own key
Thank you!
Any plans to add support for MapQuest?
We're getting an uncaught exception thrown from the geocoding.net library when we make a geocoding response that gets an OVER_QUERY_LIMIT response from Google.
I don't have good control of our C# project but we get this in our logs: 2014-06-03 15:02:58,151 WINServer [26][osthread] ERROR WINConnect.Apis.ApiExceptionHandle - Name: Geocoding, Message: There was an error processing the geocoding request. See Status or InnerException for more information.
Running wireshark shows the response from Google is good:
The exception caught in our code doesn't seem to have any useful information about the error. Do you need any more info on this?
Found problem when deploying my small application to CentOS server:
Geocoding.Microsoft.BingGeocodingException: There was an error processing the geocoding request. See InnerException for more information. ---> System.Runtime.Serialization.SerializationException: Cannot load type 'Location:http://schemas.microsoft.com/search/local/ws/rest/v1'. Error at (1,516)
at System.Runtime.Serialization.Json.JsonSerializationReader.ReadObject (System.Type type, System.Object instance) [0x0048f] in /usr/local/src/mono/mono-4.0.1/mcs/class/System.ServiceModel.Web/System.Runtime.Serialization.Json/JsonSerializationReader.cs:200
at System.Runtime.Serialization.Json.JsonSerializationReader.ReadObject (System.Type type) [0x00000] in /usr/local/src/mono/mono-4.0.1/mcs/class/System.ServiceModel.Web/System.Runtime.Serialization.Json/JsonSerializationReader.cs:72
at System.Runtime.Serialization.Json.JsonSerializationReader.DeserializeGenericCollection (System.Type collectionType, System.Type elementType, System.Object collectionInstance) [0x00247] in /usr/local/src/mono/mono-4.0.1/mcs/class/System.ServiceModel.Web/System.Runtime.Serialization.Json/JsonSerializationReader.cs:357
at System.Runtime.Serialization.Json.JsonSerializationReader.ReadObject (System.Type type, System.Object instance) [0x00419] in /usr/local/src/mono/mono-4.0.1/mcs/class/System.ServiceModel.Web/System.Runtime.Serialization.Json/JsonSerializationReader.cs:183
at System.Runtime.Serialization.Json.JsonSerializationReader.ReadObject (System.Type type) [0x00000] in /usr/local/src/mono/mono-4.0.1/mcs/class/System.ServiceModel.Web/System.Runtime.Serialization.Json/JsonSerializationReader.cs:72
at System.Runtime.Serialization.Json.TypeMapProperty.SetMemberValue (System.Object owner, System.Runtime.Serialization.Json.JsonSerializationReader jsr) [0x00019] in /usr/local/src/mono/mono-4.0.1/mcs/class/System.ServiceModel.Web/System.Runtime.Serialization.Json/TypeMap.cs:361
at System.Runtime.Serialization.Json.TypeMap.Deserialize (System.Runtime.Serialization.Json.JsonSerializationReader jsr, System.Object o) [0x000f4] in /usr/local/src/mono/mono-4.0.1/mcs/class/System.ServiceModel.Web/System.Runtime.Serialization.Json/TypeMap.cs:263
at System.Runtime.Serialization.Json.JsonSerializationReader.ReadObject (System.Type type, System.Object instance) [0x00485] in /usr/local/src/mono/mono-4.0.1/mcs/class/System.ServiceModel.Web/System.Runtime.Serialization.Json/JsonSerializationReader.cs:195
at System.Runtime.Serialization.Json.JsonSerializationReader.ReadObject (System.Type type) [0x00000] in /usr/local/src/mono/mono-4.0.1/mcs/class/System.ServiceModel.Web/System.Runtime.Serialization.Json/JsonSerializationReader.cs:72
at System.Runtime.Serialization.Json.JsonSerializationReader.DeserializeGenericCollection (System.Type collectionType, System.Type elementType, System.Object collectionInstance) [0x00247] in /usr/local/src/mono/mono-4.0.1/mcs/class/System.ServiceModel.Web/System.Runtime.Serialization.Json/JsonSerializationReader.cs:357
at System.Runtime.Serialization.Json.JsonSerializationReader.ReadObject (System.Type type, System.Object instance) [0x00419] in /usr/local/src/mono/mono-4.0.1/mcs/class/System.ServiceModel.Web/System.Runtime.Serialization.Json/JsonSerializationReader.cs:183
at System.Runtime.Serialization.Json.JsonSerializationReader.ReadObject (System.Type type) [0x00000] in /usr/local/src/mono/mono-4.0.1/mcs/class/System.ServiceModel.Web/System.Runtime.Serialization.Json/JsonSerializationReader.cs:72
at System.Runtime.Serialization.Json.TypeMapProperty.SetMemberValue (System.Object owner, System.Runtime.Serialization.Json.JsonSerializationReader jsr) [0x00019] in /usr/local/src/mono/mono-4.0.1/mcs/class/System.ServiceModel.Web/System.Runtime.Serialization.Json/TypeMap.cs:361
at System.Runtime.Serialization.Json.TypeMap.Deserialize (System.Runtime.Serialization.Json.JsonSerializationReader jsr, System.Object o) [0x000f4] in /usr/local/src/mono/mono-4.0.1/mcs/class/System.ServiceModel.Web/System.Runtime.Serialization.Json/TypeMap.cs:263
at System.Runtime.Serialization.Json.JsonSerializationReader.ReadObject (System.Type type, System.Object instance) [0x00485] in /usr/local/src/mono/mono-4.0.1/mcs/class/System.ServiceModel.Web/System.Runtime.Serialization.Json/JsonSerializationReader.cs:195
at System.Runtime.Serialization.Json.JsonSerializationReader.ReadObject (System.Type type) [0x00000] in /usr/local/src/mono/mono-4.0.1/mcs/class/System.ServiceModel.Web/System.Runtime.Serialization.Json/JsonSerializationReader.cs:72
at System.Runtime.Serialization.Json.JsonSerializationReader.ReadRoot () [0x0000d] in /usr/local/src/mono/mono-4.0.1/mcs/class/System.ServiceModel.Web/System.Runtime.Serialization.Json/JsonSerializationReader.cs:66
at System.Runtime.Serialization.Json.DataContractJsonSerializer.ReadObject (System.Xml.XmlReader reader, Boolean verifyObjectName) [0x00045] in /usr/local/src/mono/mono-4.0.1/mcs/class/System.ServiceModel.Web/System.Runtime.Serialization.Json/DataContractJsonSerializer.cs:200
--- End of inner exception stack trace ---
at Geocoding.Microsoft.BingMapsGeocoder.ReverseGeocode (Double latitude, Double longitude) [0x00000] in <filename unknown>:0
...
I tried to figure out what is going on in those source files, but either couldn't understand or find the problem... Any ideas if this is a bug in mono and if it can be fixed, or should I do something differently when using mono?
For more details, please check https://developers.openrouteservice.org/portal
Do not hesitate to ask me if you have any questions regarding the ORS API.
I had to disable the tests for now in YahooGeocoderTest
due to this issue. Not sure at which point they broke or exactly what the issue is. But either way, Yahoo only responds with a 401 Unauthorized
right now.
The Google Geocoder response contains additional data, such as viewport size information, type of address etc. However these additional items of data are ignored for the purposes of Geocoding.net - is this intentionally by design (to keep the API slim and simple)?
I'm trying to ReverseGeocode using lat-lon, and I get this exception message: "Unable to cast object of type 'd__0' to type 'GeoCoding.Microsoft.BingAddress[]'.".
My code:
IGeoCoder geoCoder = new BingMapsGeoCoder(mykey);
BingAddress[] addresses = (BingAddress[]) geoCoder.ReverseGeocode(33.941213, -84.213531);
I've also tried assigning the results of geoCoder.ReverseGeocode(....) to a var:
var addresses = geoCoder.ReverseGeocode(33.941213, -84.213531);
but there is no address data associated with it.
I have verified that my key and the lat-lon is valid:
http://dev.virtualearth.net/REST/v1/Locations/33.941213,-84.213531?o=json&key=[my key]
returns:
{"authenticationResultCode":"ValidCredentials","brandLogoUri":"http://dev.virtualearth.net/Branding/logo_powered_by.png","copyright":"Copyright © 2013 Microsoft and its suppliers. All rights reserved. This API cannot be accessed and the content and any results may not be used, reproduced or transmitted in any manner without express written permission from Microsoft Corporation.","resourceSets":[{"estimatedTotal":1,"resources":[{"__type":"Location:http://schemas.microsoft.com/search/local/ws/rest/v1","bbox":[33.93741767722188,-84.219858178107813,33.945143112363233,-84.207442573101446],"name":"85 S Peachtree St NW, Norcross, GA 30071","point":{"type":"Point","coordinates":[33.941280394792557,-84.21365037560463]},"address":{"addressLine":"85 S Peachtree St NW","adminDistrict":"GA","adminDistrict2":"Gwinnett Co.","countryRegion":"United States","formattedAddress":"85 S Peachtree St NW, Norcross, GA 30071","locality":"Norcross","postalCode":"30071"},"confidence":"Medium","entityType":"Address","geocodePoints":[{"type":"Point","coordinates":[33.941280394792557,-84.21365037560463],"calculationMethod":"Interpolation","usageTypes":["Display","Route"]}],"matchCodes":["Good"]}]}],"statusCode":200,"statusDescription":"OK","traceId":"44ea061dc0e245f2ab49dba485148eb4|BL2M002309|02.00.161.1800|BL2MSNVM001280, BL2IPEVM000008"}
Hi,
I receive this exception (sometimes) when sending geocoding requests
System.AggregateException occurred
HResult=0x80131500
Message=One or more errors occurred.
Source=mscorlib
StackTrace:
at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
at System.Threading.Tasks.Task.Wait()
at Easymage.TEC.Entities.Application.QueryHandlers.AddressSearchQueryHandler.Handle(AddressSearchQuery query) in C:\Users\Ludovic\Source\Repos\Easymage.TEC\Easymage.TEC.Entities.Application\QueryHandlers\AddressSearchQueryHandler.cs:line 32
Inner Exception 1:
GoogleGeocodingException: There was an error processing the geocoding request. See Status or InnerException for more information.
for the Google provider (Not sure about the others), if I call "Count()" on the resulting Address collection then "First()" claims there are none in the collection, even though "Count()" returns 1. Feels like Count() is unnecessarily moving and internal iterator
Need to not pass ApiKey to the service and pass a ClientId and a signature. See documentation.
Should throw an exception if ApiKey is specified with a ClientId.
Due to changes made by mapquest to their licensing structure and API the mapquest geocoding is currently broken. Requests run into a key unauthorized for request page.
See here for information on the license change: http://devblog.mapquest.com/2014/11/17/are-you-a-community-edition-licensed-data-user/
It throws a 417 if that header is included. This header can be safely removed.
Hi
I tried the examples you provided in the main page but I get the exception "Geocoding.Google.GoogleGeocodingException"
What am I doing wrong?
Thnx
Al
Keen to get my hands on the changes in v3 via nuget for my projects, is there a planned release date for this?
It looks like the old versions have this - it is a nice touch so you can wire it up through a DI framework (talking about the GoogleGeocoder specifically.
Thanks!
The following exception is thrown: Could not load type 'System.Runtime.CompilerServices.ExtensionAttribute' from assembly 'mscorlib'
This StackOverflow post describes a similar error: http://stackoverflow.com/questions/13748055/could-not-load-type-system-runtime-compilerservices-extensionattribute-from-as
This blog post describes the underlying issue: http://www.mattwrock.com/post/2012/02/29/What-you-should-know-about-running-ILMerge-on-Net-45-Beta-assemblies-targeting-Net-40.aspx
The Longitude Value does change when you get more then one GoogleGeocode at a time.
sorry my english is not good. How can I check the status of GoogleMap in c# with Geocoding.net: ZERO_RESULTS, OVER_QUERY_LIMIT, OK
In the Simple Example, listed on the front page for the project, this is listed:
IGeocoder geocoder = new GoogleGeocoder() { ApiKey = "this-is-my-optional-google-api-key" };
Address[] addresses = geocoder.Geocode("C");
Console.WriteLine("Formatted: " + addresses[0].FormattedAddress); //Formatted: 1600 Pennslyvania Avenue Northwest, Presiden'ts Park, Washington, DC 20500, USA
Console.WriteLine("Coordinates: " + addresses[0].Coordinates.Latitude + ", " + addresses[0].Coordinates.Longitude); //Coordinates: 38.8978378, -77.0365123
Notice "Address[] addresses = geocoder.Geocode("C");"
I am pretty sure that is a copy paste error, and should have been the address of the White House in stead of just "C".
I also an error in that line, regardless of value to geocode:
"Cannot convert source type 'System.Collection.Generic.IEnumerable<Geocoding.Address> to type 'Geocoding.Address[]'"
If I change things to IEnumerable and replace addresses[0] with addresses.First(), then it works.
Thank you for creating and updating the package, much appreciated. :)
Version = 3.2.1
Parameters = Longitude = -80.1373170, Latitude = 26.1224390
Error:
Value must be between -180 and 180 (inclusive).
Parameter name: Longitude
Actual value was -180.
FYI, Yahoo! shut down the PlaceFinder API that is referenced in this library. Their new service http://developer.yahoo.com/boss/geo/#placefinder has a different API.
Any plans to port this to be compatible with the PCL?
How to get nearest hospital search list with miles range (less than 50 miles, greater than 50 miles or both) based on customer address using mapquest.
please share sample MVC project
If you pass in an address that has a Zip Code that does not exist you get the following server error: Value cannot be empty. Parameter name: types.
It would be nice to have the possability to set the optional channel parameter for the GoogleGeocoder
When i use Mapquest geocode i got an error.
In Example.Web
global.asax.cs after GoogleGeocoder i have added the below MapQuestGeocoder
builder.Register(c => new MapQuestGeocoder("KEY") { UseOSM = true }).As();
Homecontroller:
var addresses = geoCoder.Geocode(address).ToArray();
return View("Index", addresses);
{"[POST] http://open.mapquestapi.com/geocoding/v1/address?key=MYKEY | EXPECTATION_FAILED | "}
Hi,
I'm doing the following...
geocoder = new Geocoding.MapQuest.MapQuestGeocoder("Foy.......") { UseOSM = true };
IEnumerable<Geocoding.Address> addresses = geocoder.Geocode(sAddressLine );
this works with both google and bing, but throws an exception when using MapQuest
oException = {"[POST] http://open.mapquestapi.com/geocoding/v1/address?key=Foy............EXPECTATION_FAILED | "}
do you have any suggestions,? thank you and great api... :)
While the v3.6.0 assembly was signed, the new v4.0.0 NuGet assemblies are not signed with a strong name.
Hello,
I am using MapQuest free vesion with UseOSM = true, and I am trying to batch geocode 100 addresses. By using fiddler I can see that the response is good, so the addresses are correclty geocoded, but I get an exception
Object reference not set to an instance of an object.
System.NullReferenceException
at Geocoding.MapQuest.MapQuestGeocoder.Parse(HttpWebRequest request) at Geocoding.MapQuest.MapQuestGeocoder.Execute(BaseRequest f) at Geocoding.MapQuest.MapQuestGeocoder.Geocode(IEnumerable`1 addresses) at ...Controller.d__13.MoveNext() in d:....Controller.cs:line 62
Thanks!
Why is XUnit required? Shouldn't only test project depend on it?
I getting this issue when I try to use the instruction below:
string Confidence = ((BingAddress[])addresses)[0].Confidence.ToString();
But works to Google:
string LocationType = ((GoogleAddress[])addresses)[0].LocationType.ToString();
What can I do?
IGeocoder geocoder = new Geocoding.Microsoft.BingMapsGeocoder("my api key here");
IEnumerable<Address> addresses = geocoder.GeocodeAsync("amsterdam").Result;
Cannot convert type Geocoding.Microsoft.Json.Resource to type Geocoding.Microsoft.Json.Location
The world we live in today is 100% async. I think that the whole api should be async and those who are needing non async can use wrappers around there code to make it sync.
This would also make the api more consistent because you can't currently do an async reverse geocode..
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.