Figure out Latitude and Longitude - android

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

Related

Getting Google Maps Intent to Return Location

So I am trying to build an app that would allows the user to select a particular place from a Google Maps intent, and when the user pick a place, the intent would finish and return the latitude and longitude data to the previous activity.
What is the best way to do this?
What I have done so far:
I used GPSTracker from here.
to get the current latitude and longitude, and then used these data to start a google map intent pointing to current location.
The website you posted in your question does not look like it contains the actual map. If you need assistance with adding a Google Map to your application I would start here.
Assuming you have that working and your code allows a user to place his or her point already, you can retrieve the coordinates of that point by using a built in function in the Marker class getPosition().
You can use the coordinates by accessing the public variables .latitude and .longitude as follows:
LatLng coord = myMarker.getPosition();
double latitude = coord.latitude;
double longitude = coord.longitude;

Wrong reading from Google Place Android API

i have developed an application that interacts with google places api to search for cafe in the neighborhood of a user. for the purpose of my application i want to have the radius set to a very small value.. may be 20 to 50 meters. currently my app is working but its not working the way it should.
In my app, i have set the radius to 350 meters. so practically it should return me the list of cafe that fall in the radius of 350m. however my app still shows starbucks in this result set even if starbucks is 650m (road distance) and 500m (straight distance). I would like to know what should be done to get the correct results.
Currently i am using GPS for this. will a combination of gps and network service provide me a better reading?
public PlacesList search(double latitude, double longitude, double radius, String types)
throws Exception {
this._latitude = latitude;
this._longitude = longitude;
this._radius = radius;
this question is not related to Android, but to the Google Places API.
are you using place search or text search? both of them have comments regarding location biasing
text search:
"You may bias results to a specified circle by passing a location and a radius parameter. This will instruct the Place service to prefer showing results within that circle; results outside of the defined area may still be displayed."
place search:
"distance. This option sorts results in ascending order by their distance from the specified location. Ranking results by distance will set a fixed search radius of 50km. One or more of keyword, name, or types is required."

How to calculate the distance between the two given latitude and longitude while Location onchanged method is called

I have some queries regarding the using the google route map , currently iam working in Android , and the application iam developing uses
google map , actually the apps i for Car hiring , suppose the client send the pickup add and destination add , now the dirver will get the request that ther
is a pickup request , now supose currently driver is in some other location (A), and his pickup request is from location (B),, no i have to calculate the distance between driver location (A) and the pickup location (B) , I tried using the method given in Android Location ,but iam not getting the correct
distance
I have use the method
float[] result=new float[5];
myLocation.distanceBetween(ServerData.LATITUDE,ServerData.LONGITUDE, latitude,longitude,result);
String distance=Float.toString(result[0]);
here
ServerData.LATITUDE----> when the driver login sends it current location
ServerData.LONGITUDE
latitude--- > is the location moving towards the pickup point
longitude
can any one suggest how to do I am stuck with it
As that function takes a double you should better use double maybe adding a line somewhere you get your coordinates from
lat = Double.parseDouble(coordinates[0]);
long = Double.parseDouble(coordinates[0]);
And as above mentioned check for result[1] as well.

How can I find the distance from a particular latitude and longitude to surrounding area in km?

I am new to Android. In my application, customer is at a location. I want to find agents near-by to that customer using his/her latitude and longitude. How can I do this? customer is on one location & We want to search agents surronding that perticular customer.
I have latitude of customer and agents and based on I want to search agents(From customer's latitude longitude in surrounding area of 5 km. which agents are thare that i want to search).
pseudocode
area = 100;
for a over allAgents
if(Math.abs(a.x - customer.x) < area || Math.abs(a.y - customer.y) < area)
nearCustomerArray.add(a);
If you already know agent's location, grab you current location using built-in device gps receiver.
Then, calculate distance between your coordinates and the one of the agent using distanceTo method of Location class
Finally, found the small distance among all the distances you calculated.

GetFromLocation method

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).

Categories

Resources