I want to create an app that list items, that get by search in google map.
Its only for display particular details about near hospital. I don't know how to convert map result into json object
I am beginner in android development
The Google Maps API provides these web services as an interface for requesting Maps API data from external services and using them within your Maps applications.
These web services use HTTP requests to specific URLs, passing URL parameters as arguments to the services. Generally, these services return data in the HTTP request as either JSON or XML for parsing and/or processing by your application.
A typical web service request is generally of the following form:
https://maps.googleapis.com/maps/api/service/output?parameters
where service indicates the particular service requested and output indicates the response format (usually json or xml).
JSON (Javascript Object Notation) has an obvious advantage over XML in that the response is lightweight. Parsing such a result is trivial in JavaScript as the format is already a valid Javascript object. For example, to extract the value of the 'formatted_address' keys within a JSON result object, simply access them using the following code:
for (i = 0; i < myJSONResult.results.length; i++) {
myAddress[i] = myJSONResult.results[i].formatted_address;
}
Use this to search places from google maps
String placesSearchStr = "https://maps.googleapis.com/maps/api/place/nearbysearch/" +
"json?location="+lat+","+lng+
"&radius=1000&sensor=true" +
"&types=hospital"+
"&key=your_key_here";
Related
I'm developing android app where I use google reverse geocoding API webservice in the user side, for the user to read his address in text format.
HttpGet httpGet = new HttpGet(
"http://maps.googleapis.com/maps/api/geocode/json?latlng="
+ lat + "," + lng + "&sensor=true");
I have the following three questions:
1-Do I have to use a map in my app?, as I'm only displaying the location in text to User and I don't want a map in my app?
https://developers.google.com/maps/terms#section_10_1
"(h) No Use of Content without a Google Map. You must not use or display the Content without a corresponding Google map, unless you are explicitly permitted to do so in the Maps APIs Documentation"
2-is it a must that I include API key at app side part of calling the webservice?
3-am I expected to establish enterprise agreement with Google, and get client_ID and include it in the request sent by the end user?
https://developers.google.com/maps/terms#section_9_1
To answer the questions:
1) I think you can use this without using the maps, for, in the API doc it said:
The Google Geocoding API provides a direct way to access a these services via an HTTP request.
https://developers.google.com/maps/documentation/geocoding/#Geocoding
2) You need an API key for using the service, even it works without using one (not recommended). Refer to this section for more information.
All Maps API applications* should load the Maps API using an API key. Using an API key enables you to monitor your application's Maps API usage, and ensures that Google can contact you about your application if necessary.
https://developers.google.com/maps/documentation/javascript/tutorial#api_key
3) for client_id, I think you don't need to unless you have to..
https://developers.google.com/maps/documentation/business/
I am planning a typical routes application for both Android and iOS, and there is something I can't replicate on Android. You can, in iOS, get some extra information about a particular point in a map by using CLPlacemark.ocean and CLPlacemark.inlandWater. Those two properties tell whether the point is over water and, in this case, the name of this water body (river X, lake Y or ocean Z)
Is there something in Google Maps API or Android SDK that might get close to that? I would be happy if only I could tell water from ground.
Thanks in advance!
P.S: sorry if iOS tag is not appropiate.
The CLPlacemark is an iOS class, so you can not use this class in Android.
Android has a Geocoder class, it can return a list of Address objects. But the Address class does not have method to tell whatever a location is in a ocean or not.
One way is to use the Google Maps Geocoding API. If your address is in land, the result_type of the response will be something like "administrative_area". if you are in the sea, the response will be "natural_feature". You can see the return type from this its documentation.
However the Geocoding API is a Javascript API, if you want to use it in Android, you can do a HTTP URL request, sample request:
URL requestUrl = new URL("https://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&key=API_KEY" );
HttpURLConnection connection = (HttpURLConnection)requestUrl.openConnection();
connection.setRequestMethod("GET");
connection.connect();
then you can parse the JSON response, and find out whether a location is in a ocean or not. Alternatively, you can use Google's Java client library for your request, sample usage: https://developers.google.com/maps/documentation/webservices/client-library#usage
You can find more information about to use Geocoding API to determine see or land from these SO answers:
https://stackoverflow.com/a/3645696/4195406
https://stackoverflow.com/a/9644812/4195406
I am trying to connect to Google Places API from an .net MVC 4 application that acts as a server for a Andorid based application as Google Places API can’t directly be contacted from the device.
Android device will send request to this .Net App and it will retrieve Places data from Google API and return it to Android device.
I am not very experienced with .Net MVC so I need to ask that is there any particular pattern or architecture I should use for this that could help me performance and productivity wise, or I can simply make web service calls from a controller and return it back?
Here is a sample request made to the places API to search for a library within a specified range of a given latitude and logitude. This uses HttpClient to send the request. Note that the response will be in json and there are a variety of ways to deserialize it and act on the data.
using (var client = new HttpClient())
{
var latitude = -33.8670522;
var longitude = 151.1957362;
var key="your api key here";
var response = await client.GetStringAsync(string.Format("https://maps.googleapis.com/maps/api/place/nearbysearch/json?location={0},{1}&radius=500&type=library&key={2}", latitude, longitude, key));
//here is an example of using Newtonsoft.JSON to deserialize the response
//json string which assumes you have a class called PlacesApiQueryResponse
var result = JsonConvert.DeserializeObject<PlacesApiQueryResponse>(response);
}
I'm using Google App Engine and Google Cloud Endpoints to communicate between my Android app (frontend) and the webservice (backend) that runs in the cloud. But I wonder about the URL's used for GET and POST.
Imagine you have a list of notes on the server each with a caption and an id. According to CRUD (create, updated, delete), the HTTP/HTTPS calls should look like that:
Get all notes:
GET http://domain.eu/notes
Get a specific note by it's id (let's say 123):
GET http://domain.eu/notes/id
and so on. But Google uses a different pattern. For instance if you use the API explorer you get calls like this:
GET https://domain/_ah/api/notesEndpoint/v1/notesdata
Question: Is there a general way to get a call for listing all notes? According to the annotations in the source code it should be somewhat like /notes or /notes.listNodes I simply don't understand how Google constructs the URL's
Google Cloud Endpoints use the API-Explorer system.
/_ah/api is defined for the API Explorer, you can't change it.
notesEndpoint is the name of your Api, and v1 the version you define.
notesdata is the name of the method. You can override the path by annotation.
Example, to access to the notes through
domain/_ah/api/notesEndpoint/v1/notes
You have to make this method :
#ApiMethod(
name = "notes.listNodes",
path = "notes",
httpMethod = HttpMethod.GET
)
public List<Foo> notesdata() {
return myList;
}
(a link to the documentation : DOC)
For information, with this system, you can explore your API with this URL :
GET http://domain.eu/_ah/api/explorer
I know the URL of accessing the google places. check here
But I am not able to parse the data coming from the URL in XML format. So, tell me the mechanism to display the data coming from google places API in xml format.
Please tell me some sample code or any tutorial for it.
Thanks in advance
You can parse it by Json.
if you see your url contains xml here . This will give response in xml.
output with xml:
<PlaceSearchResponse>
<status>REQUEST_DENIED</status>
</PlaceSearchResponse>
Just replace it with json like this . This will give response in Json.
output with Json:
{
"html_attributions" : [],
"results" : [],
"status" : "REQUEST_DENIED"
}
see this-blog for further help
For parsing
try
{
HttpPost httppost = new HttpPost("https://maps.googleapis.com/maps/api/place/search/json?&location=17.739290150000002,83.3071201&radius=6000&names=hospital&sensor=true&key=yourkeyhere");
HttpClient httpclient = new DefaultHttpClient();
response = httpclient.execute(httppost);
String data = EntityUtils.toString(response.getEntity());
System.out.println(data);
//parse with Json, Gson, Jackson
} catch (Exception e) {
e.printStackTrace();
}
First go to this. Link then other information about google places.
The Google Places API is a service that returns information about Places
— defined within this API as establishments, geographic locations,
or prominent points of interest — using HTTP requests. Place requests
specify locations as latitude/longitude coordinates.
Four basic Place requests are available:
Place Searches
return a list of nearby Places based on a user's location.
Place Details requests
return more detailed information about a specific Place.
Place Check-ins
allow you to report that a user has checked in to a Place. Check-ins
are used to gauge a Place's popularity; frequent check-ins will boost
a Place's ranking in your application's Place Search results.
Place Reports
allow you to add new Places to the Place service, and to delete
Places that your application has added.
The Places API also offers support for events, which are defined as any type
of public or private gathering, performance, or promotion that occurs at a
location listed in the Places service. For more information, see
Events in the Places
API.
(More). Here is best tutorial for how to use google places in android.
and go to this link also Google’s Places API to Develop Compelling Location Based Mobile Applications another google map example(here). Video for google developer for google places.
I think this might be helpful for you.