Hi I'm using google native geocoder class to search address.
Here is my code
final LatLng lowerLeft = SphericalUtil.computeOffset(latLng, DIST_200KM, 225);
final LatLng upperRight = SphericalUtil.computeOffset(latLng, DIST_200KM, 45);
List<Address> fromLocationName = geocoder.getFromLocationName(name, 25, lowerLeft.latitude, lowerLeft.longitude, upperRight.latitude, upperRight.longitude);
Ex:Expected search is "muruga theatre"
What i get is
Ex: 2) Typed Addr : M Address[addressLines=[0:"79, Kamaraj Salai, Ilango Nagar, Puducherry, 605013, India"], feature=79, admin=Puducherry, sub-admin=Pondicherry, locality=Puducherry, thoroughfare=Kamaraj Salai, postalCode=605013, countryCode=IN, countryName=India, hasLatitude=true, latitude=11.937229, hasLongitude=true, longitude=79.8231198, phone=null,url=null,extras=null]
Boundary lat lng: lower left ---> latlat/lng: (11.303572631938014,79.14103531980237) upper right --->lat/lng: (12.575374031508083,80.4410503605982)
Text doesnt match with the result. But the answer is correct. But when i try typing K. The address kamaraj salai wont show up.
Could anyone help me in knowing how actually geocoder class works in android.
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 am trying to create an app that will launch a Google Maps Intent that will show the route to point A, passing through points B and C. I have the addresses and the LatLng of theses points.
Until now I tried to use just make a route from one pont to another using what is in this answer but it didn't work. When the Google Maps app opens it says that no route was found. The origin and destination fields are filled with the latitude and longitude of my points.
What am I doing wrong? Is there another way of doing this?
EDIT: Code I'm using to start the intent:
double ori_latitude = -90.0000000;
double ori_longitude = -60.0000000;
double dest_latitude = -90.0000000;
double dest_longitude = -54.0000000;
String uri = String.format(Locale.ENGLISH, "http://maps.google.com/dir ?saddr=%f,%f&daddr=%f,%f", ori_latitude, ori_longitude, dest_latitude, dest_longitude);
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(uri));
intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
startActivity(intent);
Just a quick glance says your code would work, but your coordinates point nowhere special, so I wouldn't be surprised if no route existed.
From a quick test, this works for me.
Seattle, WA to San Francisco, CA
double[] origin = { 47.605617, -122.332137 };
double[] dest = { 37.774821, -122.419462 };
Uri.Builder builder = new Uri.Builder()
.scheme("http")
.authority("maps.google.com/maps")
.appendQueryParameter("saddr", String.format(Locale.ENGLISH, "%f,%f", origin[0], origin[1]))
.appendQueryParameter("daddr", String.format(Locale.ENGLISH, "%f,%f", dest[0], dest[1]));
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(builder.build().toString()));
intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
startActivity(intent);
Code you have written is correct. There is issue with these coordinates.
Try changing coordinates, and see the magic. It works perfectly.
For eg:
double ori_latitude = 34.052222;
double ori_longitude = -118.243611;
double dest_latitude = 37.322778;
double dest_longitude = -122.031944;
Also, check the rules at
Google Maps
Tips for formatting your coordinates
Here are some tips for formatting your coordinates so they work on Google Maps:
Use the degree symbol instead of "d".
Use periods as decimals, not commas.
Incorrect: 41,40338, 2,17403. Correct: 41.40338, 2.17403.
List your latitude coordinates before longitude coordinates.
Check that the first number in your latitude coordinate is between -90 and 90.
Check that the first number in your longitude coordinate is between -180 and 180.
I want the street name and longitude latitude of entered pin code in edit text as shown in the image of google map. I want to develop this type of feature in android.
Thank you in advance.
Try this,
Geocoder geo = new Geocoder(getApplicationContext(),
Locale.getDefault());
List<Address> add;
try {
add = geo.getFromLocation(taplat, taplon, 1);
addstr = add.get(0).getPostalCode();
}
I'm using MapQuest (since Google Map API will be down in september) and I'd like to add a point at an exact coordinates position.
I've created a movieClip named geoPoint and traced a circle in it.
Now, I've managed to display the coordinates in a text field like that :
if (Geolocation.isSupported){
var my_geo:Geolocation = new Geolocation();
my_geo.addEventListener(GeolocationEvent.UPDATE, onGeoUpdate);
my_geo.setRequestedUpdateInterval(50);
var my_txt:TextField = new TextField();
my_txt.wordWrap=true;
addChild(my_txt);
}
function onGeoUpdate(e:GeolocationEvent):void{
my_txt.text = "My Latitude is "+e.latitude+" and my Longitude is "+e.longitude;
}
Now is it possible to add my movieClip at the e.latitude and e.longitude point ?
I've tried :
var geo:MovieClip;
geo = new geoPoint;
addChild(geo(new LatLng(e.latitude, e.longitude)));
but it doesn't work.
Someone knows how can I do it ?
Thanks !
It should be
geo = new geoPoint();
You should also probably figure how to translate latitude and longitude to x and y coordinates, because I'm doubtful the next line will work. You're calling a MovieClip constructor that takes a LatLng argument.
For what you need to achive, you may have to use a class provided by the MapQuest Api, like PolygonOverlay or CircleOverlay. There is an example here under "Shape Collections" http://developer.mapquest.com/content/as3/v7/7.0.6_MQ/samples/samplesexplorer/index.html#
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.