I implemented the reverse geocoding in my app and it is working, but sometimes it happens a very strange issue.
The code is that
List<Address> addresses = geo.getFromLocation(
obj.getLatitude(), obj.getLongitude(), 1);
List<Address> address = geo.getFromLocationName( addresses.get(0).getLocality().getBytes() , 1 );
Address location = address.get(0);
In the first part I get the address object of the place in which I'm. Than I want recover the generic coordinates of the city in where I'm because I don't want store the coordinates of my exact position.
This is working but I encounter a very strange issue! Trying the app with the fakegps app I set my position in "Ñuñoa", and the first address was found correctly, but when I try to get the generic coordinates, I get "Nunoa" that isn't in Chile, but in Peru!!
That makes no sense! why this?
Thanks for helping me
Sure Swathi.
List<Address> addresses = geo.getFromLocation(msg_r.getLatitude(),
msg_r.getLongitude(), 1);
String geoL = addresses.get(0).getLocality() + ", " + addresses.get(0).getAdminArea() + ", " + addresses.get(0).getCountryCode();
// reverse-reverseGeocoding
List<Address> address = geo.getFromLocationName(geoL, 1);
System.out.println("Where I am? " + geoL);
Address location = address.get(0);
// generic coordinate for the locality/city/town
location.getLatitude();
location.getLongitude();
Related
I want to get values from address of Place Picker in android and separate it into different EditText like I want to set pincode on PineCodeEditText, set country on CountryEditText, set State on StateEditText and so on. I have got address as
10, Mothorowala Rd, Jagdamba Colony, Dharmpur, Ajabpur Kalan,
Dehradun, Uttarakhand 248001, India
Where I used
Place place = PlacePicker.getPlace(data,this);
String address = String.format(String.valueOf(place.getAddress()));
Before this I used Split function but it gives indexOutOfBoundException.
Any suggestion please welcome, Thank You.
You can get the latitude and longitude coordinates from the Place object, then get the address object using the GeoCoder, which you can use to get the required data separately.
LatLng coordinates = place.getLatLng(); // Get the coordinates from your place
Geocoder geocoder = new Geocoder(this, Locale.getDefault());
List<Address> addresses = geocoder.getFromLocation(
coordinates.latitude,
coordinates.longitude,
1); // Only retrieve 1 address
Address address = addresses.get(0);
String countryCode = address.getCountryCode();
String countryName = address.getCountryName();
I followed the instructions at http://dev.sygic.com/documentation/custom-url-schema/ & http://help.sygic.com/entries/22207668-Developers-Only-Sygic-implementation-to-your-app-Android-SDK-iPhone-SDK-Url-Handler-
I am passing the coordinates to Sygic 12.991030334592057 as latitude and 77.80791163444519 as longitude.
Another com.sygic.aura://coordinate|12.9138|77.6680|drive
However Sygic says 'The coordinates are outside the map.'
String str = "http://com.sygic.aura/coordinate|" + latitude + "|"
+ longitude + "|" + type.toString();
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(str)));
I also tried
String str = "com.sygic.aura://coordinate|" + latitude + "|"
+ longitude + "|" + type.toString();
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(str)));
EDIT:
The type is enum. type.toString shows drive as the string.
What am I doing wrong?
Got the same problem. As enli was saying, the order of the lat,lon params is the opposite. This code worked for me:
String str = "com.sygic.aura://coordinate|" + lon + "|" + lat + "|" + type.toString();
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(str)));
in my phone, this example call launched sygic and started navigation:
com.sygic.aura://coordinate|-3.588678|37.176278|drive
Hope it helps
There is nothing wrong with your code. Have you made sure that those values of longitude and latitude are correct? With which application you got those co-ordinates?
I was working on the same code today and it seems that I had used longitude at the place of latitude and vice versa. Try interchanging the co-ordinates. That worked for me when I was in the same boat as yours. If that is not the case, make sure that you have Sygic maps for that location by manually navigating to that location by navigating to that location from Menu > Navigate to... > GPS coordinates.
How can I get the exact Latitude and Longitude? I only get whole numbers. From my understanding, in order to get down to the meter I need to get down to 5 decimal places. I have tried the horizontal and vertical accuracy but they don't match my phones GPS reading.
How can I get an exact GPS reading with Geolocation API, Down to the meter?
here is my code
var my_geo:Geolocation = new Geolocation();
my_geo.setRequestedUpdateInterval(2000);
my_geo.addEventListener(GeolocationEvent.UPDATE, onGeoUpdate);
function onGeoUpdate(e:GeolocationEvent):void
{
gpsLat1 = (e.latitude);
gpsLon1 = (e.longitude);
gpsHeading = (e.heading);
gpsHorAcc = (e.horizontalAccuracy);
gpsVerAcc = (e.verticalAccuracy);
gpsCheck = 2;
my_txt.text = "My Latitude is "+ gpsLat1 + " and my Longitude is "+ gpsLon1 + " Bearing is " + gpsHeading+ " HorAcc "+ gpsHorAcc+ " VertAcc "+gpsVerAcc;
}
Make sure your variables (gpsLat1, gpsLon1, gpsHeading, etc.) are of type Number and not a uint or int. Unsigned Integers and Integers only allow for whole numbers, whereas Number is the equivalent of float in most other languages (and allows for incredibly larger values, as well). If you save a decimal to an integer, it is rounded off/floored (I can't remember which), which sounds exactly like the problem you are having.
Alternatively, the API is restricted by the hardware you are testing on. If the hardware only returns a certain value for GPS coordinates, AIR cannot be any more precise. Odds are this is not the issue since a whole lat long point can be miles and miles in distance, meaning any device with that inaccurate of a GPS chip is absolutely useless.
Try this:
function onGeoUpdate(e:GeolocationEvent):void
{
gpsLat1 = (e.latitude.toString());
gpsLon1 = (e.longitude.toString());
gpsHeading = (e.heading.toString());
gpsHorAcc = (e.horizontalAccuracy.toString());
gpsVerAcc = (e.verticalAccuracy.toString());
gpsCheck = 2;
my_txt.text = "My Latitude is "+ gpsLat1 + " and my Longitude is "+ gpsLon1 + " Bearing is " + gpsHeading+ " HorAcc "+ gpsHorAcc+ " VertAcc "+gpsVerAcc;
}
I am doing a location search from my android app. User enter an address and I do a lookup with the following code,
private void doSearch(String query){
FNMApplication.logInfo("Searching:"+query);
//create a geocoder
Geocoder gc = new Geocoder(this,Locale.getDefault());
try{
//lookup locations which match the query input by the user
List<Address> addresses = gc.getFromLocationName(query, 5, -44.00, 111.00, -12.0, 155.0);
//if there are any results save them in an ivar for re-use
locationSearchResults=addresses;
promptSearch();
}
catch (Exception e){
;
}
}
The bounding box above is for australia but if I search for "Los Angelos" it returns results in the US. Is there something I have missed? As I see it, it should only return addresses within the bounding box as per the reference document
From the Question I tried this and the results I got are shown below.
18.55, 72.54 = Mumbai
22.18, 70.56 = Rajkot
1)
When I pass lower latitude vaue as left lower and search for the string I got this
Geocoder gc = new Geocoder(this, Locale.getDefault());
try {
List<Address> addresses = gc.getFromLocationName("akshardham", 5,
18.55, 72.54, 22.18, 70.56);
Log.i("Address", "=========0----------------------"
+ addresses.get(0).getAddressLine(0)
+ addresses.get(0).getAddressLine(1));
Log.i("Address", "=========0----------------------"
+ addresses.get(1).getAddressLine(0)
+ addresses.get(1).getAddressLine(1));
Log.i("Address", "=========0----------------------"
+ addresses.get(2).getAddressLine(0));
Log.i("Address", "=========0----------------------"
+ addresses.get(3).getAddressLine(0));
Log.i("Address", "=========0----------------------"
+ addresses.get(4).getAddressLine(0));
} catch (Exception e) {
;
}
Logcat of this
11-17 12:42:32.419: INFO/Address(802): =========0----------------------AkshardhamNH 8C, Sector 20
11-17 12:42:32.429: INFO/Address(802): =========0----------------------AkshardhamRajkot, Gujarat 360005
11-17 12:42:32.429: INFO/Address(802): =========0----------------------Akshardham
2)
When I pass higher latitude vaue as left lower and search for the string I got this
List<Address> addresses = gc.getFromLocationName("akshardham",5, 22.18, 70.56,18.55, 72.54 );
Logcat of this
11-17 12:43:53.170: INFO/Address(837): =========0----------------------HardhamPulborough, West Sussex RH20 1
3)
The doc here itself says "The addresses matching inside the bounding box is given higher rank." , I think they mean to say, Its not necessary that If search string is address between this box only will be return,if they found the address they will return even if its out of bounding box.
I Suppose;Bounding Box is just for setting the priority of result while getting means result from the box wil be first and and then other like in get(0),get(1) of the list. but the result will be given even if they are not in bounding box.
4)
In the Geocoder.java here they are just calling the method to get addresses with passing double values as argument simple..no any checking for the result is used there else to check the lowest and highest value
=> So final answer to you problem you just call the function as you are calling and you can check the second address line that does they matches to yours means the state or country is same. to find the country,state name of your bounding box value use getFromLocation(latitude, longitude, maxResults), I still Didn't Find A Perfect Solution For this,So me too Searching
=> More on this can be explained by an expert (That's I am not) or Developer from Google itself.
I'm trying to find the address(location) using Geocoder.
I have the following code:
double lat = (double) (coord.getLat() * (1e-6));
double lon = (double) (coord.getLon() * (1e-6));
try {
List<Address> list = geocoder.getFromLocation(lat, lon,1);
if (list != null && list.size() > 0) {
Address address = list.get(0);
result = address.getAddressLine(0) + ", "
+ address.getLocality();
}
System.out.println("adresa returnata folosind geocoder:"
+ result);
}
The data that I pass to geocoder is in this format:
2.449548
48.950518
But when trying to println() the first address returned by Geocoder it returns null. This is how my logcat looks like:
reverseGeocode()`: no feature in
GLocation
And my System.out.println() displays :null. I have internet acces and also internet permssion added to my manifest file. Does someone know what I'm doing wrong??
As Geobits said, your coordinates belong to place in the Arabian Sea. You cant get an Address from there, so your list is empty and your result is null.