I want to make an android application to get weather forecast using openweathermap I from the website, I see that the URL is written like this :
[api.openweathermap.org/data/2.5/forecast/daily?lat=35&lon=139&cnt=10&mode=json]
I want to add my current location as longitude and latitude instead of constant values; I got the longitude and latitude of my current location; but I don't know how to add them into the URL.
can I use val[longitude]+val[latitude]??
If you are using java.net, yes you can do it just in plain string as:
URL urla = new URL("api.openweathermap.org/data/2.5/forecast/daily?lat="+val[latitude]+"&lon="+val[longitude]+"&cnt=10&mode=json");
I highly suggest to add org.apache.http to your project. It will make doing api call far easier than in vanilla Java.
Do you have any experience in Java? Cause I don't know if I understood your question properly.
Assuming the latitude and longitude are doubles for coordinates like this.
You'd write:
double lat, lon;
...
String newURL = "api.openweathermap.org/data/2.5/forecast/daily?lat=" + lat + "&lon=" + lon + "&cnt=10&mode=json";
That being said, this is a very basic question. I'd recommend you do the following java tutorials at
http://javala.cs.tut.fi
That system is able to grade you and I'd suggest you try to get at least 90% of the points on it.
You could try using the org.apache.http library as suggested by Arthur, but I'm afraid you might not get far if you haven't memorized the simpler Java constructs yet.
Related
I am using Geocoder from android maps api to retrieve places in android studio. It is working but not how I wanted. I want to search by location address and choose type and get all match results from that address and selected type.
String searchString = "London";
Geocoder gc = new Geocoder(this);
List<Address> list = gc.getFromLocationName(searchString, 10);
if (list.size() > 0) {
Address add = list.get(0);
String locality = add.getLocality();
Toast.makeText(this, "Found: " + locality, Toast.LENGTH_SHORT).show();
}
Can I instead put for instance London and select location type like "Stadium" and get all stadiums from london?
I have tried another solution but not sure if I can implement it to the Android, which is googleapis that retrieve JSON:
http://maps.googleapis.com/maps/api/geocode/json?address=stadium+Near+London=true
It gives me correct answer but only one results,
I have two questions here:
1. how can I get all match stadiums?
2. Can I implement it in an android app? like reading retrieved json data from the app?
I believe that you should actually be using the places API for Android instead of the geocoder. The geocoding API isn't really intended for returning multiple results of a certain type, but the place API is. Please see the article on getting place predictions programmatically here:
https://developers.google.com/places/android-api/autocomplete#get_place_predictions_programmatically
This will allow you to bias results to a certain area, such as london. And allow you to return results of a certain type, such as stadiums. While this may not be exactly what you are looking for, I believe this is the closest thing Google provides. You may also want to take a look at the other things the Places API for Android can do here:
https://developers.google.com/places/android-api/start
I hope this helps!
Hi I am new to android development.
I am on college project its based on location which is need to find list of latitude and longitude in between two points.
Given Starting position is 12.990143,80.215784 and destination position is 12.992595,80.217618.
Over the past days i search the google, i found so many links to find distance between locations and mid point. I cant able to find solution for my problem.
Please suggest some solution for this problem. I am struggling over days to find solution for this.
Thanks in advance
You can use the SphericalUtil.interpolate method from the Google Maps API Utility Library.
For example you can find a LatLng that is at 1/5 of the distance between your starting position and your destination by doing
LatLng origin = new LatLng(12.990143,80.215784);
LatLng destination = new LatLng(12.992595,80.217618);
LatLng result = SphericalUtil.interpolate(origin, destination, 0.2);
You can use the google Directions api to obtain a full PolyLine of the path. You can objain a JSON object and parse it to obtain locations in the path.
http://maps.googleapis.com/maps/api/directions/json?origin=12.990143,80.215784&destination=12.992595,80.217618&mode=driving
This will return a full JSON result which contains everything you would need to find the whole route to all the points falling on it.
You can look more into it on:
https://developers.google.com/maps/documentation/directions/intro#Introduction
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 need lat and lng of a point on a google map. It has to look like that
8.53171539306641 for example
but when I go to maps.google.com I get just
8.532493
There is a possibility to receive lat and lng that have such a length 8.53171539306641 but I do not remember how
I am sure you would have looked into this: Try receiving the value in a double precision data type.
If this doesn't solve it, could you please paste some code for us to get a good sense of what exactly you are trying to achieve.
Does anyone know how to display points, lines etc. (basically every overlay) created in android in standard google maps on website? The android db is synchronized with remote db. I'm getting the points from the database, creating kml file from them and uploading in to the map. The problem is that the areas I've created are not appearing where they should. They're somewhere on the ocean. I thought that's because I'm running this code in android:
Double lat = location.getLatitude()*1E6;
Double lng = location.getLongitude()*1E6;
So basically I'm doing microdegrees here. I thought that dividing lat and long from db by 1E6 would do the trick but it didn't. Can someone please help me on that one? Thanks in advance.
I don't know which format is expected by the map.
If it is normal coordinates, then I guess you would need to do:
float lat = ((float)location.getLatitude()) / 1E6;
Otherwise, if it is expecting it in int format, you don't need to do anything
P.S. Assuming getLatitude() returns an int, the cast to float is important. Otherwise 4539845 will become 45 and not 45.39845
I agree with ltsik, the E6 format is basically the regular latitude multitplied by 1E6 (or 1,000,000 whichever one you prefer) so it makes perfect sense that the variables lat and lng are obtained by dividing and not multiplying