I'm using getThoroughwayfare() to get street names but when on a highway / interstate the method returns null. I couldn't find another method that could detect interstates. Has anyone been able to successfully detected interstates?
Thanks
Ok, Its quite old question, but i think i answer for somebody else.
I too need to get information whether i was on interstate or not and Geocoder was of no help.
So i came across Google geocode api which gives plenty of information.
e.g
LatLng: 39.249121,-122.182131
And Url would be:
https://maps.googleapis.com/maps/api/geocode/json?latlng=39.249121,-122.182131&sensor=false
sensor is true in case you sending from mobile and false if using browser.
Now you can open the link and check the detailed reply for yourself, in those json objects, you will get a type = route and you will get I-5 as the short_name of road you are on.
Related
Hello my fellow coders,
I am trying to retrieve GeoCoordinates from an Android Google Maps SEND Intent (as dispatched when selecting to share a selected location) and even after searching around and trying various approaches for hours now I can't seem to get anywhere. However, all I seem to get from the Intent seems to be a text/plain content like this:
Franziskaner Wirtshaus & Biergarten - Trudering-Riem, München
https://some/shortened/maps/link
I tried (amongst others) several approaches from:
Get GeoCodes from Android Google Maps App (Not applicable since it opens a new activity)
How can I find the latitude and longitude from address? (Geocoder and Geocoding REST API from Google - no suitable results)
None of the above solutions yields any usable results.
Is there a reliable way to get GPS coordinates from something a user selected in Google Maps on Android at all?
Thanks in advance for your help,
Alex
I don't know if this app helps you. you can copy coordinates to clipboard or open it with other third party maps
cheers
I have contacted Open Weather Map support team last week and their forum is dead. Hopefully get some help on here.
I am currently building a weather app for android.
when I send the lat and long for Birmingham UK
which are
lat 52.4447615﹕
lon -1.9292798
it returns Vietnam as the country with a completely different lat lang? I know open weather map is very popular so I must be constructing the url wrong or
something.
http://api.openweathermap.org/data/2.5/weather?q=lat=52.4447462&lon=-1.9292798&units=metric
would really appreciate any help. Thanks,
Matt
It seems the problem is the units argument. Just get rid of it and it works:
http://api.openweathermap.org/data/2.5/weather?lat=52.4447615&lon=-1.9292798
Please note I have not read through the API documentation, just started from their overview page here:
http://openweathermap.org/current.
Try this : [openweathermap.org]1
You can also use Geocoder to get city name from co-ordinates.
I am working on the developement of an android app. I need to locate the user without displaying the map (only the name of his location ei New york, USA)
I work using Eclipse SDK.
Is there a way to do it?
Thanks :)
Ps: I am new to android
Android API Maps
In the API documentation it shows you step by step how to get started on this
type of application.
How to get started
One thing you have to remember is that the user must enable
the GPS to get current location
Since you explained in comments that you already know how to get the Location, and thus the latitude and longitude, you can resolve it to an address using Android's GeoCoder class, with its getFromLocation(double,double,int) method.
I want to open Google Maps in Navigation mode from a mobile web link. This seems easy enough for iOS devices using https://developers.google.com/maps/documentation/ios/urlscheme
Is there an equivalent for Android? All I could find was this: https://developer.android.com/guide/appendix/g-app-intents.html
But that doesn't allow you to specify "transitmode" and the other parameters needed to get directions as far as I can tell.
Actually, a slight modification of the methods described in the iOS Doc would work here too (I tested it before putting it here albeit, in a native app and not a web link).
The parameters necessary for this to work are pretty much the same as with the ones listed in the iOS documentation:
From the iOS Docs:
Parameters:
saddr: Sets the starting point for directions searches. This can be a
latitude,longitude or a query formatted address. If it is a query
string that returns more than one result, the first result will be
selected. If the value is left blank, then the user’s current
location will be used.
daddr: Sets the end point for directions searches. Has the same
format and behavior as saddr.
directionsmode: Method of transportation. Can be set to:
driving, transit, or walking.
They are actually, pretty much the same. They are however, no where to be found in the documents. Also, while the first 2 parameters work the usual way here, the last parameter directionsmode does not work as is. A workaround is however, listed below.
That being said, a simple URL can be constructed that can then be passed as an Uri to an Intent that will then handle the application to be launched (Google Maps if installed and/or list of browsers to choose from)
String mapURL = http://maps.google.com/maps?saddr=-33.9417, 150.9473&daddr=-33.92050, 151.04287&dirflg=d
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(mapURL));
startActivity(intent);
A few variations for the Transit Mode:
&dirflg=d = for Driving directions (this is the default mode. leaving it out is the same as putting it in explicityly).
&dirflg=w = for Walking directions
&dirflg=r = for Public transit.
&dirflg=b = for Biking directions.
That being said, at the time of running these test (I admit I was curious enough to test a little further after seeing this question ;-) ), the modes listed in the Travel Modes section don't seem work!
A little proof of sorts:
Note: Credit for the initial discovery of the options
I've created an autocomplete address search text box. My problem is that I just can't make it work fine:
Addresses are out of the bounding box usually, whatever I do - this didn't help.
Finds addresses that doesn't contain the typed text.
Finds less addresses, than max but it doesn't contain the good result.
The result list is totally irrelevant sometimes.
I need to type almost the whole address to get the correct result.
Source:
Geocoder geocoder = new Geocoder(this, Locale.getDefault());
List<Address> addresses = null;
try {
if (Geocoder.isPresent()) {
// Bounding box: Hungary
addresses = geocoder.getFromLocationName(text, 5, 46.13, 21.96, 48.89, 16.69);
}
} catch (IOException e) {
Log.v(tag, "Geocoding error: " + e.getMessage());
e.printStackTrace();
}
My aim is to make an address search text box which gets the same result as in Android Maps seach text box - except the previously typed/favourite addresses and etc., which is an other story.
The Google Places Autocomplete API may be of help. As far as I know you must license it for use in commercial apps. If your app is for free then you should be fine.
EDIT about inaccurate Geocoder results:
I haven't yet played around much with Geocoder. But what I can tell you so far is the following:
You need to take into consideration that on some devices all methods return null (check Geocoder.isPresent() to be sure) because Geocoder relies on some underlying implementation that can be missing on some devices.
And it is also possible that these results come from an other Geocoder engine / service than Google Places.
On top of that the query results are never perfect. You rarely get the exact address of the current location either because the location is off or because the Geocoder data is not accurate enough (or simply outdated).
If you really need an accurate address you should give the user both a list of best candidate options and some means for manually editing the address.
If you need more accurate results based on the location name you could take a look at available online services that perform better for your needs. One example is geonames.org. If their database is good enough for you, then you need to get or implement some Java API for interfacing with the service of your choice and use that instead Geocoder.