Why if I take the andress with this code List<Address> loc = getFromLocation(lat,long,1); the address is correct but the civic number is wrong because if I put the latitude e longitude into Sygic it give me another civic number.
Example :
Via Merulana 19,Roma (with getFromLocation)
Via merulana 15/16,Roma
(with sygic when I put the longitude and latitude)
Because they are different services. getFromLocation uses the reverse geocoding provided by Google, as for Sygic, they probably use their own service. Reverse geocoding isn't expected to have that degree of accuracy (ie match the exact house number).
Related
I'm currently building a location based app that relies on the lat and long of the devices being properly translated to a text location.
My current problem is as follows (using lat/long -37.8047079,144.9641467 as an example):
Both
Places API
https://maps.googleapis.com/maps/api/place/textsearch/json?query=-37.8047079,144.9641467&key
and
Geocode API
https://maps.googleapis.com/maps/api/geocode/json?address=-37.8047079,144.96414677&key
return: "8-14 Little Queensberry St, Carlton VIC 3053, Australia"
However for some reason or another when the same lat long is typed into google maps itself it results in the location 135 Queensberry St, Carlton VIC 3053
Which is a major problem for me due to the routes API returning that same later address Causing a mismatch between the two services
Am i doing something wrong and if i'm not, is there a way around it?
Note that the second address is the one that i deem as "correct"
Thanks in advance !
When you execute a reverse geocoding you should use latlng parameter instead of the address parameter. So the query
https://maps.googleapis.com/maps/api/geocode/json?latlng=-37.8047079%2C144.96414677&key=MY_API_KEY
returns several items. The first one is Shop2/143 Queensberry St, Carlton VIC 3053 of type establishment, restaurant and the second one is 135 Queensberry St, Carlton VIC 3053, Australia of type street_address.
You can see these results in Geocoder tool:
https://google-developers.appspot.com/maps/documentation/utils/geocoder/#q%3D-37.804708%252C144.964147
It looks like restaurant is closer to the coordinate that you provided. However if your intention is getting back a street address just filter the reverse geocoding results by street address type.
https://maps.googleapis.com/maps/api/geocode/json?latlng=-37.8047079%2C144.96414677&result_type=street_address&key=YOUR_API_KEY
This request will return expected result.
I hope this helps!
I am trying to develop an android application that can do task according to the lat/long. This is something like if I am in particular suburb (Lets say I am in Belconnen, ACT Australia, I would like to get the details of that place automatically) - if I move out the border of belconnen then I have to show some other details.
If you check this google maps link: http://goo.gl/4mItcF you would see the red border is only belconnen suburb.
My question is how do I give the borders in my App (meaning how do I tell my App that I am now in belconnen, ACT? Is it by getting lat/long along the borders store them in DB and check if I am inside required lat/long, if that is the case DB would have huge numbers only for Belconnen, ACT right?
Or is there an easier way to get the borders?
Let me know!
Thanks!
There is a way , it is called Reverse Geocoding. You can use it by two ways :
1. Using Geocoder class of Android -
Geocoder gcd = new Geocoder(context, Locale.getDefault());
List<Address> addresses = gcd.getFromLocation(lat, lng, 1);
if (addresses.size() > 0)
System.out.println(addresses.get(0).getLocality());
Here you use lat = -35.2374551 and lng = 149.0672515 for Belconnen, ACT Australia. Check out the function getFromLocation for more information.
2. Using Google REST Web Services :
https://maps.googleapis.com/maps/api/geocode/json?latlng=-35.2374551,149.0672515 (JSON)
https://maps.googleapis.com/maps/api/geocode/xml?latlng=-35.2374551,149.0672515 (XML)
pass comma separated latitude and longitude and u will get the most precise location for that in response. Find more information here Reverse Geocoding google API
As soon as you go out of Belconnen, ACT Australia, the address in response will no longer contain this and you can put some logic to get your desired behavior.
As far as i understand, you would like to create a Location Aware Application.
As per the Android documentation, Google Play services location APIs are preferred over the Android framework location APIs (android.location) as a way of adding location awareness to your app.
Step 1 - Knowing the current Location of the User
Google recommends to use FusionProvider API for this purpose. It is one of the location APIs in Google Play services where you can specify requirements at a high level, like high accuracy or low power. It also optimizes the device's use of battery power.
https://developer.android.com/reference/com/google/android/gms/location/FusedLocationProviderApi.html
Step 2 - Based on the latitude and Longitude information retrieved in the location object, you can use the below Google web service to get the postal code of the location.
http://maps.googleapis.com/maps/api/geocode/json?latlng=lattitude,longitude&sensor=true
Step 3 - How Frequent can we retrieve the location information
Turning on the listeners continuously will impact the device battery highly. So, to avoid this, we need to minimize the frequency of retrieving the location information.
I would recommend to measure the distance traveled by the user and based on that set the next location update trigger. Since you are concerned about boundary only, we can set a high value based on the device acceleration.
Refer the below links for more details on how to implement this effectively.
https://stackoverflow.com/a/11644809/623517
Hope this helps.
You can get full address from lat long and then search your city or location. This answer explain how to do it : How to get complete address from latitude and longitude?
If you want further flexibility you can use geofence : http://developer.android.com/training/location/geofencing.html
You can approximate the region with LatLngBounds (com.google.android.gms.maps.model.LatLngBounds).
Use it like this:
LatLngBounds.Builder builder = new Builder();
for (int i=0; i<points.length; i++) {
builder.include(points[i]);
}
LatLngBounds bounds = builder.build();
And then check if your location falls inside it:
if (bounds.contains(myLatLng)) {
//your implementation
}
I know this approach cannot give perfect results but it seems to be more efficient then using the geofences.
LocationManager lm;
lm=(LocationManager)this.getSystemService(Context.LOCATION_SERVICE);
Criteria c=new Criteria();
String provider=lm.getBestProvider(c, false);
Location l=lm.getLastKnownLocation(provider);
double latitude = l.getLatitude(); // latitude
double longitude = l.getLongitude(); // longitude
I'm using Android's Geocoder to get street and suburb for my App, however on some roads, it will return State Route 60 for example, rather than the actual road name.
I'm in Western Australia if that makes any difference.
Is there a way around that ?
Or will I have to guess the street based on latitude and longitude ?
And in the same vein - the Geocoder returns streets as "St" and Roads as "Rd".
I can't find a default way of expanding that. If there is one, I would love to know about it.
I ended up changing the amount of addresses that the getFromLocation method returned to 2, and then adding logic in to detect when the first address is returned contained State Route.
When the first address returned State Route, it would use the second returned address instead.
In my app, I have a list of locations, and I want to create filter settings. I am looking for a way so that a user can pick maybe a continent or country or address and then filter out the locations from the list if the location is within the continent or country or close to the address.
Is there a google maps v2 api for android that can do something like:
public Boolean AddressIsContained(String address, String place);
which returns true if address is within place (place could be like a country or continent). And also like
public Boolean AddressCloseTo(String address1, String address2, int distance);
which returns true if address1is within distance amount of kilometers to address2. And this would just be a straight line between the addresses, nothing like a bike, walk, car or plane route.
Also for the list of locations, I am also able to access its lat/long if that makes it easier.
Thanks
For the start I assume you are familiar with the GeoCoder and / or GeoCoding API to get the addresses for your locations.
If you use the GeoCoder you will get a List of Address objects. The Address class provides some methodes to get the country or city name f.e. These methods you can use for your filter.
The Location class includes the methods distanceBetween() and distanceTo(). These you can use to check the distance between your locations.
guys.
Method getFromLocationName(..) in Geocoder class return Addresses by "a user-supplied description of a location". And if I'm calling it with "London" string or "Statue of Liberty" it returns addresses and I can animate the Map to found coordinates. But iI need to find latitude and longitude based on ZIP CODE. If I call method with "33040" string (zip of Key West region) - Geocoder returns some another addresses (of course!), because it can't associate this string with zip.
I have made some trick: adding "usa " prefix if user enters decimal value. And it returns currect locations by string "usa 33040" and others in 70%. Is any idea how to find location by ZIP in 100% cases? Thanks!
Have you tried strings like "33040, United States"? That format certainly works in Google Maps, so it may work on Android, though the Android geocoder is not as good as that Google Maps uses.