Android Maps Coordinates - android

I am getting json response from an Api. The response looks like this.
{
"CarsList": [{
"coordinate": {
"latitude": 53.46036882190762,
"longitude": 9.909716434648558
},
"heading": 344.19529122029735
},
{
"coordinate": {
"latitude": 53.668806556867445,
"longitude": 10.019908942943804
},
"heading": 245.2005654202569
},
{
"coordinate": {
"latitude": 53.58500747958201,
"longitude": 9.807045083858156
},
"heading": 71.63840043828377
}
]
}
I need to create custom list items using the json Response data.
I am using latitude and longitude to get the location. I am confused as to what the "heading" parameter represents. Please help me in figuring out the purpose of this "heading" parameter. Thanking in advance.

Here is a definition of heading in the google documentation:
When navigating on a sphere, a heading is the angle of a direction from a fixed reference point, usually true north. Within the Google Maps API, a heading is defined in degrees from true north, where headings are measured clockwise from true north (0 degrees).
Also you can see how it is calculated visually:
https://developers.google.com/maps/documentation/javascript/examples/geometry-headings

Related

Sort firebase databse using an object inside an array in Android

I want to sort a list in firebase realtime database using orderByChildValue(). But the value is inside an array.
How to do that?
Database
{
"partners": [
{
"full_name": "Alex Smith",
"partner_roles": {
"role1": [
{
"latitude": 9.84945654,
"locality": "location1",
"longitude": 76.32834545
},
{
"latitude": 9.81232145,
"locality": "location2",
"longitude": 76.34229345
}
],
"role2": [
{
"latitude": 9.84945654,
"locality": "location1",
"longitude": 76.32834554
}
]
}
}
]
}
Here i want to return all the items role1/locality equals location2
i tried using:
database.child("partners")
.orderByChild("partner_roles/role1/locality")
.equalTo(location1)
But it returns empty and It returns items if the database is like:
{
"partners": [
{
"full_name": "Alex Smith",
"partner_roles": {
"role1": {
"latitude": 9.84945654,
"locality": "location1",
"longitude": 76.32834545
},
"role2": {
"latitude": 9.84945654,
"locality": "location1",
"longitude": 76.32834554
}
}
}
]
}
The value to order/filter on must be at a fixed path under each child node of the path where you execute the query. That is not the case when the value is in an array. In fact, in your case there may even be multiple values for each node, which is something Firebase queries don't support.
As is common when dealing with NoSQL databases, the solution is to change or augment your data model to allow the use-case. Since you're looking to load partners by their locality, add a node with exactly that information. Something like:
{
"partner_localities": {
"location1": {
"partner1": {
"full_name": "Alex Smith",
"role": "rol1"
}
}
}
}
Now you can find all partners at location1 by loading the data from partner_localities/location1. I've duplicated some of the data about the partner in the node, but you should tune that to whatever works best for your data model.
Also see:
Firebase query if child of child contains a value
Firebase Query Double Nested

Launch Android Map intent with specific direction overlay from directions API result

I'm making a navigation application, I have a bunch of routes being returned from Googles Directions API (set alternatives to true), which the user will then choose from. What I'd like to do is launch the Map intent for Google Maps with the selected route passed in.
I'm wondering if this is possible?
I've seen examples of passing in saddr and daddr which will automatically show the best route, but instead I'd like it to display the one selected by a user from one of the direction results which may not the best (most optimum).
Thanks
After reading the google direction api, I saw that in its response type (https://developers.google.com/maps/documentation/directions/intro#sample-response), we have for every step, latitude and longitude defined.
Say your output route looks like (this is dummy, not original):
{
...
"routes": [ {
"summary": "I-40 W",
// There are many legs, but say user choses this below first leg.
"legs": [ {
"steps": [
{
"travel_mode": "DRIVING",
"start_location": {
"lat": 41.8507300,
"lng": -87.6512600
},
"end_location": {
"lat": 41.8525800,
"lng": -87.6514100
},
"polyline": {
"points": "a~l~Fjk~uOwHJy#P"
},
"duration": {
"value": 19,
"text": "1 min"
},
"html_instructions": "Head \u003cb\u003enorth\u003c/b\u003e on \u003cb\u003eS Morgan St\u003c/b\u003e toward \u003cb\u003eW Cermak Rd\u003c/b\u003e",
"distance": {
"value": 207,
"text": "0.1 mi"
}
},
{
"travel_mode": "DRIVING",
"start_location": {
"lat": 41.8107300,
"lng": -87.6012600
},
"end_location": {
"lat": 41.8725800,
"lng": -87.6414100
},
"polyline": {
"points": "a~l~Fjk~uOwHJy#P"
},
"duration": {
"value": 19,
"text": "1 min"
},
"html_instructions": "Head \u003cb\u003enorth\u003c/b\u003e on \u003cb\u003eS Morgan St\u003c/b\u003e toward \u003cb\u003eW Cermak Rd\u003c/b\u003e",
"distance": {
"value": 207,
"text": "0.1 mi"
}
}
"start_address": "Oklahoma City, OK, USA",
"end_address": "Los Angeles, CA, USA"
} ],
.... // many other legs ....
"legs":[ { ..... } ]
.
.
"copyrights": "Map data ©2010 Google, Sanborn",
...
..
.
} ]
}
]
}
Now, above for each step, we have lat and lng entries. We will use those to create our intent request.
Our request will become :
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("https://maps.google.ch/maps?saddr=Oklahoma City, OK, USA&daddr=Los Angeles, CA, USA to:41.8525800,-87.6514100 to: 41.8107300,-87.6012600"));
startActivity(intent);
Notice that I have used the steps lat and lng along with to: prefix in the url. Use can use only upto two to: prefixes in this url, because google maps app doesn't acknowledge all the waypoints but only the first and the last, when passed as intent.
To put it generalized way :
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("https://maps.google.ch/maps?saddr=[address1]&daddr=[address2] to:[address3] to: [address4]"));
startActivity(intent);
So, this will open google maps app with navigation marked from [address1] to [address2] passing through [address3] and [address4].
Hope this solves problem.

Request buildings around and area osm android

I would like to perform a request to OSM Overpass Turbo API or Overpass API from and Android Application so i can get the buildings around and area using JSON.
Something similar to
http://overpass-turbo.eu/ with the query presented below:
[out:json][timeout:25];
// gather results
(
// query part for: “building”
way["building"](37.98350674557998,23.72600823640823,37.98552989685638,23.728837966918945);
relation["building"](37.98350674557998,23.72600823640823,37.98552989685638,23.728837966918945);
);
// print results
out body;
>;
out skel qt;
The thing is that i need the results in geojson like the result below but i cannot find any query that gives me the below result.
{
"type": "FeatureCollection",
"generator": "overpass-turbo",
"copyright": "The data included in this document is from www.openstreetmap.org. The data is made available under ODbL.",
"timestamp": "2015-03-23T20:41:02Z",
"features": [
{
"type": "Feature",
"id": "relation/2604192",
"properties": {
"#id": "relation/2604192",
"building": "yes",
"type": "multipolygon"
},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
23.7319885,
37.9752441
],
[
23.7319787,
37.9751612
],
[
23.7319494,
37.9751641
],
[
23.7319372,
37.9748376
],
[
23.7319702,
37.9748318
],
]
]
}
},
I get only results with nodes but not with geometry.
{
"type": "way",
"id": 25107859,
"nodes": [
2373953582,
2373953586,
2373953592,
2373953599,
2373953597,
2373953636,
2373953633,
2373953626,
273319309,
2373953582
],
"tags": {
"building": "yes"
}
},
After some useful comments (thanks scai) i found out that overpass turbo is not queried automatically. Therefore i searched for overpass api and i found out this site with a query for buildings to overpass api exporting to GeoJSON but i does not work (though the xml query in the site works but i need json). Anyone has a query that works so i can follow it?
http://inasafe.org/en/developer-docs/osm_building_downloads.html
http://overpass-api.de/api/interpreter?data=[out:json];(node[%23building%22=%22yes%22](-6.185440796831979,106.82374835014343,-6.178966266481431,106.83127999305725);way[%22building%22=%22yes%22](-6.185440796831979,106.82374835014343,-6.178966266481431,106.83127999305725);relation[%22building%22=%22yes%22](-6.185440796831979,106.82374835014343,-6.178966266481431,106.83127999305725););(._;%3E;);out%20body;

Parsing JSON in android to add markers in Google Map

I have an url,get and response given. I have to parse the JSON and show the locations in Map in android. I dont need you to code. I am new in JSON. please tell me some steps how i can do that. how should i start and which steps i should take?
Url: "Some url"
Sending data:
{
"tag": "getAvailableDriver",
"lat": 41.022348,
"lng": -91.966721
}
RESPONSE:
{
"posts": [
{
"success": "1",
"driver": [
{
"id": "768",
"lat": "41.022848",
"lon": "-91.966884",
"recorded_datetime": "2014-07-20 20:18:03",
"user_id": "403",
"cabbi_state": "OnJob",
"vehicleType": "Black Cab",
"driver_name": "black cab driver",
"pic_name": "userimage/403.jpg",
"rating": "0",
"car_model": "this",
"number_sit": "4",
"distance": 0.035574527536789
}
],
"operator": [],
"nearestdistance": [
{
"distance": 0.03541809,
"time": 5
}
],
"car_models": [
"Taxi"
]
}
]
}
I just want anyone of you to guide me or show me the way. And also please someone tell me what will be the use of "send data" here. What is the use? I promise i will not ask any basic questions after i catch the grip. Help me please.
You can save the parsed data in an array, and for what I can see, there's a lot of tags in the JSON object. I suggest you to create an object of the type "Driver" or "Car", and then save all the data in that object. Once you have the data parsed and saved in an Array of the type of your object (Let's say an array of "Drivers" then you can use the info to add it into the Map.

Finding driving directions using google in iOS, Android and Windows Phone app

I'm developing a iOS, Android and Windows Phone app, all in native language. Atm I'm calculating distance between current location and a list of points. Here's a sample on how i do this on Android:
Location currentLocation = new Location( "CurrentLocation" );
Location.distanceBetween(mLatitude, mLongitude, tempLoc.getLatitude(), tempLoc.getLongitude(), results);
Problem is that Location.distanceBetween gives me a distance in birds eyes, i would like to change this to give me the distance for driving directions(fastest route)(only need the distance, not drawing it out on a map). I'm not even sure if this is possible. So i got 2 questions.
Is this even possible with google API?
If yes, what options do i have(keep in mind that developing for 3 platforms)?
Thanks in advance.
You could ask Google API for the driving route between those two points, and iterate over each step, which includes the distance.
https://developers.google.com/maps/documentation/directions/#JSON
For example, you could do a request like this:
http://maps.googleapis.com/maps/api/directions/json?origin=Chicago,IL&destination=Los+Angeles,CA&waypoints=Joplin,MO|Oklahoma+City,OK&sensor=false
but using coordinates instead of addresses. The result would be something like this:
{
"status": "OK",
"routes": [ {
"summary": "I-40 W",
"legs": [ {
"steps": [ {
"travel_mode": "DRIVING",
"start_location": {
"lat": 41.8507300,
"lng": -87.6512600
},
"end_location": {
"lat": 41.8525800,
"lng": -87.6514100
},
"polyline": {
"points": "a~l~Fjk~uOwHJy#P"
},
"duration": {
"value": 19,
"text": "1 min"
},
"html_instructions": "Head \u003cb\u003enorth\u003c/b\u003e on \u003cb\u003eS Morgan St\u003c/b\u003e toward \u003cb\u003eW Cermak Rd\u003c/b\u003e",
"distance": {
"value": 207,
"text": "0.1 mi"
}
},...
Maybe you could add the distance value of each step: 207 + ...

Categories

Resources