Missing Pin Codes in Google Maps API - android

I have an android app that handles logistics for me in my city (Mumbai, India). The user types in his address followed by his pin code. I use google maps API to find the (lat, long) of the area marked by the pin code and calculate which one of my stores is closest to it. That store fulfills the customer's order. So far it has been fairly successful but recently I discovered some users orders were not tended to because an error was returned on querying the pin code's location.
This is the url i send an HttpRequest to
"http://maps.googleapis.com/maps/api/geocode/json?components=postal_code:"+uri[0]+"|country:india"
So for example if I type the link below. I get the approximate location of the vicinity marked as 400006
"http://maps.googleapis.com/maps/api/geocode/json?components=postal_code:400006|country:india"
But If i input some pin codes such 400036, where I have been getting orders from the JSON I get returned is this
{
"results" : [],
"status" : "ZERO_RESULTS"
}
Could someone please help me out/ explain what exactly is happening. There are a few other pin codes where I am not getting a result.

Related

Google directions api return zero results for some Addresses

I have studied all previous questions but did not found solution. I'm working on Google Directions API,to draw route in android. I am getting addresses from Google Places and it draws a route but there are many places where Directions returns no result.While I have checked google map and some other apps they render the same address.Then I tried the simple query in browser but the problem remains same.Help me please I am stucked here, I will be very thankful to you.Origin address is problamatic
Here is my query
https://maps.googleapis.com/maps/api/directions/json?origin=University%20of%20gujrat,gujrat,punjab,pakistan&destination=gujranwala,punjab,pakistan&key=
And the example address is "University of Gujrat, Gujrat, Punjab,Pakistan"
I am attaching browser output. Thanks in advance.
browser output
I actually tried your given query and it returned a "status" : "OK".
However, for some addresses that you got zer0_results, as discussed in Directions Response Elements, the following are the indications of values in the status field within the Directions response:
NOT_FOUND indicates at least one of the locations specified in the request's origin, destination, or waypoints could not be geocoded.
ZERO_RESULTS indicates no route could be found between the origin and destination.
To avoid these error codes, please check parameter values that you have entered in your HTTPS Directions requests. As standard in URLs, all parameters are separated using the ampersand (&) character. The list of parameters and their possible values are enumerated in Request Parameters.

How to tell if the city is incorrect in Android openweatherMap API?

I'm using XmlPullParser to parse the weather information from the API. My application shows the weather information once the user entered his city (input). If I enter enter "London" in the text box, my app goes to this and fetches the temperature, humidity etc. from the xml (at this point everything works as expected). But when I enter "Londonsd" my app hangs up.
Message I'm getting from the server when I enter incorrect city is "{"message":"Error: Not found city","cod":"404"}".
You are getting two types of data responses in case of success get xml and in case of failure getting json make them identical first. I will suggest use json by changing mode=json http://api.openweathermap.org/data/2.5/weather?q=London&mode=json&units=metric.
After that you can put a check on cod if there is 404 then city is invalid.
or
You can try response.contains("\"cod\":\"404\""); or response.contains("Not found city"); for checking error. but not ideal solution.

Google Places Autocomplete Details API

I am in the process of making an android application with a location field so am using Google Places Autocomplete in order to assist the user. Once they select a choice from the list, I am then getting the place_id from the response and using that to get the full address and coordinates. However, I am seeing inconsistent results. For example, if I have an address typed in I get the following in the response:
"place_id" : "ChIJhV00Saykj4ARf5pLLQUgXh8",
"reference" : "CkQ4AAAA6Oz4yvX3mdvSp_NuluEW-aMS5Kg6j0gNDxjidPUbnqsNrm17-Am4C8HwIBMfNXK20UvsrZt7MnJ1MeV3-N6kqxIQrIQn113f7ksZNBoX2NBVahoU4p6yZwFFSlTP5jZUXib5CO7uO5k",
If I use that place_id for a details request, I am missing the street_number, which was included in the previous response. If I use the reference in the details request, then I get the correct location, with the street_number along with a different place_id.
"place_id" : "ChIJm5jeVKykj4ARICvBIsIA2MI",
After reading the docs, they said reference will be depreciated and I should use place_id but it is not working properly. Does anyone know why or what is your solution for a place details request?

How to make From/To Address text fields in Android using GPS and maps marker?

Hello mighty developers,
I am coding an android application to send a request to a taxi.
I've already got Android Maps API v2 setup and the map fragment is working fine.
I need to code a text field for the "From" address and another one for the "To" address
I need to be able to enter the address via text or post code and then the app will give me the option to choose the most accurate address from the choices, I also want to be able to retreive the current location of the mobile into the text field via GPS and via Network provider. Finally, I need to be able to fine tune the location chosen using a marker on the map fragment.
How on android earth can I do that ?
Im developing on Android API 8 Froyo btw as I need the app to be compatible with the most android phones possible.
Cheerio, all you cool coders
a lost developer
What have you already tried?
The "hardest" part might be verifying the address they enter... but there are some APIs which make this pretty easy. I work at SmartyStreets, and LiveAddress API is one such service you could use. A simple HTTPS request can provide to you a list of suggested/candidate addresses. For example:
https://api.smartystreets.com/street-address?street=1600+amphitheatre+parkway&city=mtn+view&state=ca&zipcode=&auth-id=<your auth ID>&auth-token=<your API key>
The result would be:
[
{
"input_index":0,
"candidate_index":0,
"delivery_line_1":"1600 Amphitheatre Pkwy",
"last_line":"Mountain View CA 94043-1351",
"delivery_point_barcode":"940431351000",
"components":
{
"primary_number":"1600",
"street_name":"Amphitheatre",
"street_suffix":"Pkwy",
"city_name":"Mountain View",
"state_abbreviation":"CA",
"zipcode":"94043",
"plus4_code":"1351",
"delivery_point":"00",
"delivery_point_check_digit":"0"
},
"metadata":
{
"record_type":"S",
"county_fips":"06085",
"county_name":"Santa Clara",
"carrier_route":"C058",
"congressional_district":"14",
"rdi": "Commercial",
"latitude": 37.41907,
"longitude": -122.07764,
"precision": "Zip7"
},
"analysis":
{
"dpv_match_code":"Y",
"dpv_footnotes":"AABB",
"dpv_cmra":"N",
"dpv_vacant":"N",
"ews_match":false,
"footnotes":"B#N#"
}
}
]
If the address is ambiguous, a few options will be returned which you can show to the user so he/she can choose one of them.
And you mentioned ZIP codes: there's a SmartyStreets endpoint to validate ZIP codes and cities/states too.
For displaying a marker on the map, the Google Maps API has functions available for this.

How to use Google Places API in Android?

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.

Categories

Resources