vivet / googleapi Goto Github PK
View Code? Open in Web Editor NEWC# .NET Core Google Api (Maps, Places, Roads, Search, Translate). Supports all endpoints and requests / responses.
License: MIT License
C# .NET Core Google Api (Maps, Places, Roads, Search, Translate). Supports all endpoints and requests / responses.
License: MIT License
traffic_model (defaults to best_guess) — Specifies the assumptions to use when calculating time in traffic. This setting affects the value returned in the duration_in_traffic field in the response, which contains the predicted time in traffic based on historical averages. The traffic_model parameter may only be specified for requests where the travel mode is driving, and where the request includes a departure_time, and only if the request includes an API key or a Google Maps APIs Premium Plan client ID. The available values for this parameter are:
best_guess (default) indicates that the returned duration_in_traffic should be the best estimate of travel time given what is known about both historical traffic conditions and live traffic. Live traffic becomes more important the closer the departure_time is to now.
pessimistic indicates that the returned duration_in_traffic should be longer than the actual travel time on most days, though occasional days with particularly bad traffic conditions may exceed this value.
optimistic indicates that the returned duration_in_traffic should be shorter than the actual travel time on most days, though occasional days with particularly good traffic conditions may be faster than this value.
Hi,
For some reason Language attribute is not working on QueryAutoComplete.
e.g. Language = "pt-BR" returns me "State of São Paulo" instead of "São Paulo" or "Estado de São Paulo"
I've tested Language on Google Place - Autocomplete and it works well.
Sorry for my english, and thanks for this library.
It looks to me that the current implementation doesn't allow to filter by multiple countries, since Dictionary<> doesn't allow to have non-unique keys. I wonder if I'm missing something?
components — A grouping of places to which you would like to restrict your results. Currently, you can use components to filter by up to 5 countries. Countries must be passed as a two character, ISO 3166-1 Alpha-2 compatible country code. For example: components=country:fr would restrict your results to places within France. Multiple countries must be passed as multiple country:XX filters, with the pipe character (|) as a separator. For example: components=country:us|country:pr|country:vi|country:gu|country:mp would restrict your results to places within the United States and its unincorporated organized territories.
Hi,
We're looking to use the Distance Matrix API and come across your wrapper (which looks really useful, thanks!).
The DistanceMatrixRequest
has the Origins
and Destinations
properties that both take an IEnumerable<Location>
. The Location
class currently has one constructor that takes a lat and long. Would it be possible to take a second constructor where we can pass an address string instead? The documentation indicates that this is an acceptable request.
If you're happy for the change to be implemented I could clone and PR it?
Thanks,
Lee & @Dingwall
Hi,
var request = new PlacesAutoCompleteRequest
{
Key = _key,
Input = filter,
Sensor = false,
Language = "en",
Types = new List<RestrictPlaceType>() { RestrictPlaceType.CITIES }
};
var response = await GooglePlaces.AutoComplete.QueryAsync(request);
This code doesn't work, but it works perfectly if I replace RestrictPlaceType.CITIES by RestrictPlaceType.ESTABLISHMENT
Hi there
I just looked at the code, and you've obviously put a lot of work into it. Please consider making this portable (.net standard). You seem to be maintaining it actively (kudos for that!), but in its current state, it's obsolete for many projects, I'm afraid...
Thanks,
Philipp
I dont see a method to specificy, either globally or individually the google API key to use for each service.
Thanks.
I need to pass the channel parameter to all Google Places API requests, but I cannot find it in PlacesAutoCompleteRequest or PlacesDetailsRequest. How can I do it?
Regards,
Stefan
When using country restriction ("cr") in search request, only one country can currently be specified.Also query infomation returned in search response needs proper deserialization of country restrictions.
Google supports multiple restrictions using logical operators.
https://developers.google.com/custom-search/docs/xml_results_appendices#booleanOperators
Configure Travis.yml to properly build and run test suite using environmental variables for Google parameters. Finally, publish new Nuget package automatically.
Hi, I'm using your component for extensive GeoCoding, and found that some of the places listed at https://developers.google.com/places/supported_types are not available in GoogleApi.Entities.Common.Enums.LocationType, and it gives an exception when trying to parse the whole response, so the response.Results are always null.
Hi, I saw that there's no parameter place_id in GeocodingRequest in order to execute this request on Maps:
https://developers.google.com/maps/documentation/geocoding/intro#place-id
Thanks.
As detailed at https://developers.google.com/places/web-service/search, Google are deprecating the ability to use multiple types when performing Nearby Searches, but this API only offers a Types
property on the PlacesNearBySearchRequest
which doesn't give me confidence that it has been updated accordingly. Multiple types will stop working on February 16, 2017. Is there a plan to fix this?
Hi there
Love your work. Really great API. Hey I've just upgraded to the latest nuget package and have a whole bunch of errors related to GeocodingResponse not being contained in the assembly. Is there something I'm doing wrong, or is this a legit bug?
Cheers
Ren.
Hey,
I've tried to add your NuGet package to one of my solutions:
Could not install package 'GoogleApi 2.0.7'. You are trying to install this package into a project that targets '.NETFramework,Version=v4.5', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.
Hi,
When adding enum AvoidWay to Avoid property i get "Index was outside the bounds of the array" on calling DistanceMatrix.Query(matrixRequest) . If Avoid property is not given any value, everything works like a charm.
Thanks
EDIT: Sorry, I just found the Place Details API. Thanks ! :)
Hello,
Is there a way to get an address with the placeID ? I can't find the method to find an address by passing its placeID.
Could please help me ?
Thank you,
Christophe.
I am unable to use the nuget package for this API because when I try to run, it is unable to get the correct version of Newtonsoft.Json because VS 2012 can only go up to 9.6. Unforunately I can't get a different version of VS because of my work, we are upgrading next year to 2017. Below is the exception:
"An unhandled exception of type 'System.IO.FileLoadException' occurred in GoogleApi.dll
Additional information: Could not load file or assembly 'Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)"
I am unable to do anything until I update to version 10.0 or higher for that nuget package. I was able to load it on a newer version of VS, but as I said that isn't a solution because of everyone else on my team using the older version of VS.
Hi,
I have that map with 58 markers.
I put that 58 locations as path to the SnapToRoadsRequest
instance but I only get 5 SnappedPoints
back.
Any idea?
I put the JSON response (my data where I put the snappedPoints inside) as gist
Here my code:
public sealed class GoogleMapsApiHelper
{
public static string ApiKey { get; set; }
public static IEnumerable<TruckFahrerGeoDataWithSnapToRoad> GetSnapToRoadPoints(TruckFahrerGeoData[] truckFahrerGeoData)
{
//TODO make method ASYNC !!!
// TODO That current only worksd with a max. of 100 waypoints !. Adjust when prototyp is working.
List<TruckFahrerGeoDataWithSnapToRoad> truckFahrerGeoDataWithSnapToRoadPoints = new List<TruckFahrerGeoDataWithSnapToRoad>();
int currentIndex = 0;
foreach (TruckFahrerGeoData fahrerGeoData in truckFahrerGeoData)
{
truckFahrerGeoDataWithSnapToRoadPoints.Add(new TruckFahrerGeoDataWithSnapToRoad
{
Id = fahrerGeoData.Id,
FahrerId = fahrerGeoData.FahrerId,
Imei = fahrerGeoData.Imei,
Latitude = fahrerGeoData.Latitude,
Longitude = fahrerGeoData.Longitude,
TimeStamp = fahrerGeoData.TimeStamp,
SnappedPoint = default(SnappedPoint),
Name = fahrerGeoData.Name,
TelemetryData = fahrerGeoData.TelemetryData,
SnappedPointIndex = currentIndex
});
currentIndex++;
}
Location[] requestPath = truckFahrerGeoDataWithSnapToRoadPoints
.Select(geo => new GoogleApi.Entities.Common.Location((double) geo.Latitude, (double) geo.Longitude))
.ToArray();
/*
* TODO
*
* 1. get the lat/lon points out of the truckFahrerGeoData array as an array of Location instances
* 2. build the SnapToRoadsRequest with each of the lat/lon points
* 3. pass the request to the SnapToRoad.Query method and invoke
* 4. get the result.SnappedPoints?.ToArray();
* 5. add each SnappedPoint by its INDEX to the truckFahrerGeoDataWithSnapToRoadPoints.IndexOf(INDEX)
*
* */
SnapToRoadsRequest request = new SnapToRoadsRequest
{
Key = GoogleMapsApiHelper.ApiKey,
Path = requestPath
};
SnapToRoadsResponse response = GoogleMaps.SnapToRoad.Query(request);
if (response.SnappedPoints == null)
return truckFahrerGeoDataWithSnapToRoadPoints;
SnappedPoint[] snappedPoints = response.SnappedPoints.ToArray();
foreach (SnappedPoint snappedPoint in snappedPoints)
{
TruckFahrerGeoDataWithSnapToRoad truckFahrerGeoDataWithSnapToRoad =
truckFahrerGeoDataWithSnapToRoadPoints.FirstOrDefault(tfg => tfg.SnappedPointIndex == snappedPoint.OriginalIndex);
if (truckFahrerGeoDataWithSnapToRoad != null)
{
truckFahrerGeoDataWithSnapToRoad.SnappedPoint = snappedPoint;
}
}
return truckFahrerGeoDataWithSnapToRoadPoints;
}
}
Thanks in advance.
best
Eric
PlacesDetailsRequest is not inheritance from SignableRequest. Therefor we can not use premium licence
Please add the support
Two fields should be added to the response data:
profile_photo_url
relative_time_description
I received the below error when running a GooglePlaces TextSearch
When I took the raw query url and ran it I received the below json result and the place type for "Kippel Islands" returned "archipelago" as a place type. I did not see this place type listed in the Google Places documentation here https://developers.google.com/places/supported_types#table1 nor did I see it in the source code under PlaceLocationType.cs or in SearchPlaceType.cs. Since this is not in the Google list I am not sure if this is a bug for you or for Google but I did want to bring this to your attention.
{
"html_attributions" : [],
"results" : [
{
"formatted_address" : "422 Scenic Hwy, Rosslyn QLD 4703, Australia",
"geometry" : {
"location" : {
"lat" : -23.170764,
"lng" : 150.789462
},
"viewport" : {
"northeast" : {
"lat" : -23.1692183197085,
"lng" : 150.7908517802915
},
"southwest" : {
"lat" : -23.1719162802915,
"lng" : 150.7881538197085
}
}
},
"icon" : "https://maps.gstatic.com/mapfiles/place_api/icons/generic_business-71.png",
"id" : "56e230c8281a5f73fc7af328bd172276e6c3a41e",
"name" : "Great Keppel Island Security Carpark",
"place_id" : "ChIJT75mX7jowmsREWtTFKft68I",
"reference" : "CmRSAAAAzGEoKySUuVbrDa6RF7_lIMKbV7idMz_wx6G16Z8_BuzMcS3QzrBv7Z9oVVZOrGdb0TTZ2kWts7rGRpFSg_EqqveVpKO9jRjYbMdXKcZ9d06Cxakw0k31eTJajfMB5FSMEhAJAwcTujtyD9wYpbD-yi6XGhSWdT8exuLrR-_mrIR63wLHS5gB4w",
"types" : [ "parking", "point_of_interest", "establishment" ]
},
{
"formatted_address" : "Kippel Islands, The Keppels QLD 4700, Australia",
"geometry" : {
"location" : {
"lat" : -23.1238609,
"lng" : 150.9773282
},
"viewport" : {
"northeast" : {
"lat" : -23.0255836,
"lng" : 151.0937206
},
"southwest" : {
"lat" : -23.2221382,
"lng" : 150.8609358
}
}
},
"icon" : "https://maps.gstatic.com/mapfiles/place_api/icons/geocode-71.png",
"id" : "f00c5c3f175778691a4658a083618b2e548b0e51",
"name" : "Kippel Islands",
"place_id" : "ChIJE6LOUCiVwmsRdE8rZVhsaTE",
"reference" : "CmRbAAAAJpdXVffaZIiVW4F2qysJnzuxpG9G0Ro8mNHuYJzFLzthZ3qw7SdNgEHbtj4AuDHHW0R4IupCPmzKj3kM3yk5nK65y1mgWnhW-05VQ1CXp1sHndia4yVwwfjY3ow8B1IqEhDCYYew_iC0RmcpESG4lrRbGhRWht9fmNHoALfCwOrPax5Ha0fa2A",
"types" : [ "archipelago", "natural_feature", "establishment" ]
},
{
"formatted_address" : "The Esplanade, Great Keppel Island QLD 4703, Australia",
"geometry" : {
"location" : {
"lat" : -23.17872599999999,
"lng" : 150.93353
},
"viewport" : {
"northeast" : {
"lat" : -23.17737701970849,
"lng" : 150.9348789802915
},
"southwest" : {
"lat" : -23.1800749802915,
"lng" : 150.9321810197085
}
}
},
"icon" : "https://maps.gstatic.com/mapfiles/place_api/icons/lodging-71.png",
"id" : "0adfede43599267d7df63d076231a5e87244135b",
"name" : "Great Keppel Island Hideaway",
"opening_hours" : {
"open_now" : false,
"weekday_text" : []
},
"photos" : [
{
"height" : 657,
"html_attributions" : [
"\u003ca href=\"https://maps.google.com/maps/contrib/111980555853980672916/photos\"\u003eGreat Keppel Island Hideaway\u003c/a\u003e"
],
"photo_reference" : "CmRaAAAAVuXvoXEoDK2gLnG5Bnigc5z0s3IG4_l5_lMSxDvfex8oEeLU73nx-aHFgljBZj68LKFqzipgYp4GgavJEVCtyFDHZQm6nvmJT0S7hCwkGf1W7qmXmJBP72RKUkC1sHNDEhDrKx-tjd85K8rEzKHyeQbkGhTLvRQQKs5HKgQvwvhYAOtKemvW6g",
"width" : 1027
}
],
"place_id" : "ChIJGTmmhiLrwmsRv8goXhzLNPw",
"rating" : 4.2,
"reference" : "CmRSAAAA1pDRHVwNR7pugGd2XpvUdqNVrq8AwHeiaf_k-rldmyQeC9HYSlethPTFEZqT-e5RUbRPAYKpFATQM48wTD41XuitZdJqhkqdQnW3VKGhcPU5hLIK59cIwaXPJDJ5Q4ZcEhA5n9dyGCacG1gQN-c72su5GhTWm0gRukcAQKfHGU8MCLtt2o5qpA",
"types" : [
"bar",
"lodging",
"restaurant",
"food",
"point_of_interest",
"establishment"
]
},
Really useful library, thanks for your work on it. I've just encountered this issue when searching for a place via a string, and then getting the full place details:
await GooglePlaces.Details.QueryAsync(request);
The PlaceId I am retrieving is: EiQxMjkgVGF1bnRvbiBSZCwgTGVlLCBMb25kb24gU0UxMiwgVUs
The exception stacktrace I get is:
Newtonsoft.Json.JsonSerializationException : Error converting value "postal_code_prefix" to type 'GoogleApi.Entities.Common.Enums.LocationType'. Path 'result.address_components[7].types[0]', line 43, position 44.
----> System.ArgumentException : Requested value 'postal_code_prefix' was not found.
at Newtonsoft.Json.Converters.StringEnumConverter.ReadJson(JsonReader reader, Type objectType, Object existingValue, JsonSerializer serializer)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.DeserializeConvertable(JsonConverter converter, JsonReader reader, Type objectType, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateList(IList list, JsonReader reader, JsonArrayContract contract, JsonProperty containerProperty, String id)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateList(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, Object existingValue, String id)
Implement easier access to advanced features of Google Search.
For example:
Same issue as: #50
Wouldn't it be better to use a custom deserializer for Google enums to fallback on unknown
in case of new/not-yet-known type ? (or add an option to deserialize as a string for enum values)
I'm under the impression that Google modifies the list quite often...
Hi,
Could you provide a sample on how to use the Snap to Road functionality with your .Net port when having more than 100 waypoints. Do you care about that google limitation?
Best
Eric
Its not really clear if an IP reports errors through an error response or a http exception.
Go through BaseRespoonse and HttpEngine.
NOTE: currently Response.Status defaults to 'OK', hiding errors in tests..
Roads and Geolocation tests are not covering, Fix them
Hi there, I am getting this issue
'GoogleApi.Engine.FacadeEngine`2<GoogleApi.Entities.Maps.DistanceMatrix.Request.DistanceMatrixRequest,GoogleApi.Entities.Maps.DistanceMatrix.Response.DistanceMatrixResponse> GoogleApi.GoogleMaps.get_DistanceMatrix()'.
is this a bug or did I do something wrong?
Can you please send me some documentation on how to use your API or a website that has any information?
Thank you.
If you try to use RankBy.Distance
when making a nearby places search, you are told that the radius must be specified. This goes against the Google documentation at https://developers.google.com/places/web-service/search, which states that radius should not be specified if the RankBy is changed. If you do set a radius, you get an InvalidRequest
returned, presumably because the library is specifying both parameters.
This project is very useful for xamarin mobile applications, but can not install this in portable classes libraries, you can install this on Android Project and iOS project but not in the portable class library. The .dll is not added.
var privateKey = this.FromBase64UrlString(request.Key);
But request.Key is the API Key, not the private crypto key for Client ID
You will get an System.FormatException.
If you provide departure time in request. Google will respond with duration and duration_in_traffic.
Both values are avialable in Json but not in response.
Add Property to Element.cs
Hello,
I want to use the GoogleFunctions.EncodePolyLine with DistanceMatrixRequest how can I achieve this?
Thanks
Hello,
I tried auto complete for 'Places' and it works great. The issue is, when I try to filter by 'Cities', google returns:
predictions | [] |
---|---|
status | "INVALID_REQUEST" |
I checked the exception I got, and the request url is like this:
If I try to run it on my browser like this:
https://maps.googleapis.com/maps/api/place/autocomplete/json?key=[MY_API_KEY]&sensor=false&input=Nic&language=en&types=(cities)
it works fine.
For more info please check how I am constructing my query in C#:
var request = new PlacesAutoCompleteRequest
{
Key = apiKey,
Input = input,
Types = new List<RestrictPlaceType>() { RestrictPlaceType.Cities }
};
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.