I am using Google Places API to search nearby hospitals from a location. My problem is that I want to get famous and big hospitals but the problem is the API is fetching clinics and even dental clinics too. How I can be more specific?
Query URL : https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=24.9044526,67.077706&type=hospital&radius=500&key=[API_KEY]
Although they are not famous even the medical facilities provided there are not sufficient for emergency case.
I have also tried increasing the radius but got same response.
I know this post is a bit old but this worked for me:
var request = {
location: location,
rankBy: google.maps.places.RankBy.DISTANCE,
type: "hospital",
keyword: "(emergency) AND ((medical centre) OR hospital) AND (24 hours)",
};
service = new google.maps.places.PlacesService(map);
service.nearbySearch(request, callback);
Related
Google forces us to migrate from the deprecated Contacts API over new People API.
They even implemented "Other Contacts" feature in the People API which was so demanded.
But now I'm facing another problem - there is no way to get photos of Other Contacts in the People API.
I was digging into this problem and figured out that it's possible to add photos into the readMask (even though it's not documented):
https://people.googleapis.com/v1/otherContacts?access_token=<...>&readMask=emailAddresses,names,photos
...but it doesn't help, because it returns the default picture with the first letter for all contacts, even for contacts who has a real photo. Like this one: https://lh3.googleusercontent.com/cm/ABXenNkcRSTRZU8PEFQfJtaeEBZnxLgN-UO555npUt1idzcMohoSGuJFfKx0JX2AR6Qp=s100
I tried to add coverPhotos into the readMask but it doesn't let it there.
Then I was checking how old Contacts API formats photo urls and figured out the format:
https://www.google.com/m8/feeds/photos/media/<user-email-address>/<contact-id>
But it has 2 disadvantages:
this url has to be requested with access_token
it works only if the contact uploaded a custom photo, otherwise it returns error
So here is my question:
Is there any simpler and cleaner way to get real photos of Other Contacts in People API?
This bug has been solved and now we have a solution!
Updated documentation: https://developers.google.com/people/api/rest/v1/otherContacts/list
There is a new sources[] request parameter. To get the real photos of "other contacts" you need to specify 2 values: READ_SOURCE_TYPE_CONTACT and READ_SOURCE_TYPE_PROFILE.
The request would look like this:
GET https://people.googleapis.com/v1/otherContacts?readMask=photos&key=API_KEY&sources=READ_SOURCE_TYPE_CONTACT&sources=READ_SOURCE_TYPE_PROFILE
Now some contacts will contain 2 entries in the photos array:
photos: [
{
metadata: {
primary: true,
source: {
type: "PROFILE",
id: "11111"
}
},
url: "<THIS IS THE REAL PROFILE PICTURE>"
},
{
metadata: {
source: {
type: "OTHER_CONTACT",
id: "6666666"
}
},
url: "<THIS IS THE DEFAULT PHOTO STUB>",
default: true
}
]
The readMask fields accepted for the otherContacts.list method are the following:
emailAddresses
metadata
names
phoneNumbers
photos
As you can notice, the photos field is an accepted one while making the above request.
However, the returned response should yield a url which redirects you to the user's profile picture. Because of this, I have taken the opportunity to report it on Google's Issue Tracker here. I suggest you star the issue as any updates regarding this will be posted there.
Reference
People API otherContacts.list;
People API Support.
I need help with my code.
First, is my approach correct that I use the GoogleDistanceMatrix to get the real route distance and not just the linear distance?
I want to use an Geocoordinate for the origin and destination Adress but it doesnt seem to work:
public double CalculateGoogleDistance(GeoCoordinate from, GeoCoordinate to) {
DistanceMatrixRequest request = new DistanceMatrixRequest();
request.Key = "****";
request.Origins = new Location[] {
new Location(from)
};
request.Destinations = new Location[] {
new Location(to)
};
var response = GoogleApi.GoogleMaps.DistanceMatrix.Query(request);
return response.Rows.First().Elements.First().Distance.Value;
}
First off, you appear to be using 3rd party libraries/repositories in using Google Maps API services, so I would advice that you only follow their official documentations, in which I will be providing as I answer your questions.
As mentioned in their official documentation, even though it is optional, the default trafic_model is bestguess, meaning that the result will be based on the best estimate of travel time given what is known about both historical traffic conditions and live traffic. You can learn more about the other traffic model optional parameters here.
Now, with regards to getting "real route distance", you are only referring to the live result excluding historical traffic. To get this, you would need to specify the departureTime to now as given in the example from the doc:
drivingOptions: {
departureTime: new Date(Date.now() + N), // for the time N milliseconds from now.
trafficModel: 'bestguess'
}
As you can see, that is how Distance Matrix API works.
Note: The departure time and traffic model is also applicable to Directions API.
See this link for the web service version of Distance Matrix API web service.
I am having problems understanding the Google Places API. I am building an iPhone application with a nearby feature that allows the user to find restaurants located around the user's GPS. How can I obtain a Google API for this? Do I have to have one custom made how does this work? If I also wanted to create an API for points of interest how can I do that?
There is a Google Places API for searching for nearby locations. The documentation is here: https://developers.google.com/places/documentation/search#PlaceSearchRequests
But I'm guessing you already found that. If you ask more specific questions, we can be more helpful.
You can use Google place API , and if you want to display only specific type of places e.g restaurant in your cases you can use request object as shown in the code below
var request = {
location: pyrmont,
type: ['restaurant']
};
infowindow = new google.maps.InfoWindow();
places = new google.maps.places.PlacesService(map);
places.nearbySearch(request, callback);
For more details on type filteration in google place API you can check the Link on Google Developers.
But nearby search taking only one type parameter, and it is only restaurants. Not food, not cafe, only restaurants, which Google API provides, if you are looking for the public catering establishments.
First of all, the Google Paces API should be active.
function displayRestaurantAround() {
return new Promise((resolve, reject) => {
this.service.nearbySearch({
location: currentUserPosition,
radius: 5000,
types: ['restaurant']
}, (res) => {
resolve(res);
});
});
}
When you search for a restaurant in Google places and go to the business profile (i.e.:
https://plus.google.com/107507038669791289691/about?hl=en) the restaurant has a tag (in this case Mexican Restaurant). But when using the Google places api all I can see is a types list
"types" : [ "restaurant", "food", "establishment" ]
Anyone know if it's possible to get the tag "Mexican Restaurant" somehow?
I know about the supported types (https://developers.google.com/places/documentation/supported_types). It is not super helpful.
I was also working in a project which need to get more details about a place using Google Maps and Google Places APIs, and I really spent many hours trying to find something that can help ( Google Places API, Google Maps API, google+ APIs, ... ) but nothing ... the only things that I found is theses 2 issues ( feature requests ) which I hope that Google will add to their APIs someday :
Issue N° 5260 with 13 stars.
Issue N°7878 with 4 stars.
I hope with this SO question that we get more interested persons to get the feature in a soon future version of Google Map or Google Places APIs.
For the Google Places for Work API, I didn't find any information to confirm or not that it contains such feature, but I don't think so.
Hope that can help.
I think you would probably have to revert to the text search method on the api..
https://developers.google.com/places/documentation/search#TextSearchRequests
So your request would end up looking something like the below, restricted down to a specific area
https://maps.googleapis.com/maps/api/place/textsearch/json?query=Mexican+Restaurant&sensor=true&location=40.846,-73.938&radius=20&key=yourKeyHere
However this will return all other Mexican restaurants in the area, so if you just want to return the one result I would use the Place Details request instead.
Separate your place types by PIPE symbol "|"
try like this :
String types = "cafe|restaurant|museum" // Listing places only cafes, restaurants and museums.
is there a way to use core location or google or some other api to provide two points on the map and get the resulting set of latitude/longitude pairs for the route?
i have seen in this tutorial Drawing polyines or routes on a MKMapView that how to draw driving direction using core graphics...but in the sample code it has route.csv which has predefined set of longitudes and latitudes.....how do i make pair of longitudes and latitudes so that i can draw driving directions.
Companies invest millions of dollars into developing routing algorithms, so I very much doubt that you'll be able to get it for free anywhere (I'm happy to be wrong, though). For example, the Google Maps JavaScript API supports routing, so I guess you could hack that up. The results wouldn't be fast or pretty, mind you.
If you have a limited use of the directions request (less than a certain amount per day) and always display results on a Google map, you do qualify for the free Google Directions API.
https://developers.google.com/maps/documentation/directions/
Read the license part thoroughly to know the limits. You should easily be able to request a json response that will b easier to parse than an xml one (plus Apple added json parser in iOS).
For example
http://maps.googleapis.com/maps/api/directions/json?origin=Boston,MA&destination=Concord,MA&waypoints=Charlestown,MA|Lexington,MA&sensor=false
If you are over the limit, you should look into their business licenses.
Old question but MTDirectionsKit was recently open sourced and it works great:
MTDirectionsKit
with Google API you can get directions from two points, the only problem is you just can use it once a day if you don't pay.
Search how to get the key API from google, there are a lots of videos on youtube talking about it.
Furthemore, i got a library which hepls you to draw the line between points this one https://github.com/jd-alexander/Google-Directions-Android
After you implemented it in build.gradle(Module:app), implement the library in the class like
public class LocationMapActivity extends AppCompatActivity implements RoutingListener
will appear a error to implemets the methods (obligatory to implement them but It's not necessary to use them).
I just did this:
public void route(){
Routing routing = new Routing.Builder()
.travelMode(/* Travel Mode */)
.withListener(/* Listener that delivers routing results.*/)
.waypoints(/*waypoints*/)
.key(/*api key for quota management*/)
.build();
routing.execute();
}
More info in the link.