Starting point always invalid (681) (Skobbler Android API) - android

I am trying to generate a route using the Skobbler Android SDK and I cannot seem to pass a valid starting point.
It is always returning the error code 681, despite trying numerous different latitude longitude pairs.
SKRouteSettings route = new SKRouteSettings();
route.setStartCoordinate(new SKCoordinate(51.510537, -0.183426));
route.setDestinationCoordinate(new SKCoordinate(51.510943, -0.151020));
route.setNoOfRoutes(1);
route.setRouteMode(SKRouteSettings.SKROUTE_CAR_FASTEST);
route.setRouteExposed(true);
SKRouteManager.getInstance().setRouteListener(this);
SKRouteManager.getInstance().calculateRoute(route);
Then on completion of route calculation:
if (statusMessage != SKRouteListener.ROUTE_SUCCESS) {
runOnUiThread(new Runnable() {
#Override
public void run() {
Toast.makeText(DisplayMessageActivity.this, "Route calculation failed: " + errorNo, Toast.LENGTH_SHORT).show();
}
});
return;
}
The starting and end points are situated in London.
I am using a modified demo project.
Thank you.

Due to historical reasons the Android SKCoordinate constructor expects a (longitude, latitude) pair - instead of the more common (lat, long) pair.
So replacing your code with:
route.setStartCoordinate(new SKCoordinate(-0.183426,51.510537));
route.setDestinationCoordinate(new SKCoordinate( -0.151020,51.510943));
will fix the issue.

Related

Google map direction intent with multiple location on route and starting point as current location, android

I want to start Google map intent for direction with current location as starting position, one location as entry position and other location as destination.
After googling for this, following is the closest query I came with
https://maps.google.com/maps?f=d&daddr=41.3951982,-72.855568 to: 41.279386, -72.825098
OR
"https://www.google.com/maps/dir//41.3951982,-72.855568/41.279386,-72.825098"
Both of them work good when I paste on browser, but not on my mobile device. I just get source and destination. Any ideas?
EDIT:
Actually the second one works. Unlike browser, it only shows starting location and first point, but has a full navigation route. :)
There isn't any google approved way of doing it (as far as I looked to documentation). But I found this solution working pretty good
private void navigate(List<LatLng> latLngs) {
String uri = "";
for (LatLng latLng : latLngs) {
if (TextUtils.isEmpty(uri)) {
uri = String.format(
"http://maps.google.com/maps?saddr=%s, %s",
String.valueOf(latLng.latitude).replace(",", "."),
String.valueOf(latLng.longitude).replace(",", ".")
);
} else {
if (!uri.contains("&daddr")) {
uri += String.format(
"&daddr=%s, %s",
String.valueOf(latLng.latitude).replace(",", "."),
String.valueOf(latLng.longitude).replace(",", ".")
);
} else {
uri += String.format(
"+to:%s, %s",
String.valueOf(latLng.latitude).replace(",", "."),
String.valueOf(latLng.longitude).replace(",", ".")
);
}
}
}
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(uri));
startActivity(intent);
}
Google Maps app on Android doesn't support multiple destinations. You can try to draw on the map by using native Google Maps Android API. You can get the directions from Google Maps Directions API.

Google Place API doesn't find everywhere (everything)

I'm trying to develop my own map. I have got ahead till somewhere. Now i'm trying to add place filter on my app. So i reached and found this link
I implemented and it works. But the problem is it doesnt find all bus stations or all banks around me. I'm from Turkey and i thought maybe it could work well in USA but it connects to GPS so i couldn't try for different state (country).
Does anyone know, how i can handle with this?
Just temporarily use hard-coded values for latitude and longitude in order to test your code with any location you want.
Replace your code with this in order to test your code with San Francisco as a location:
#Override
public void onClick(View v) {
double testLat = 37.7942635; //added
double testLon = -122.3955861; //added
int selectedPosition = mSprPlaceType.getSelectedItemPosition();
String type = mPlaceType[selectedPosition];
StringBuilder sb = new StringBuilder("https://maps.googleapis.com/maps/api/place/nearbysearch/json?");
sb.append("location=" + testLat + "," + testLon ); //modified
sb.append("&radius=5000");
sb.append("&types="+type);
sb.append("&sensor=true");
sb.append("&key=YOUR_API_KEY");
// Creating a new non-ui thread task to download json data
PlacesTask placesTask = new PlacesTask();
// Invokes the "doInBackground()" method of the class PlaceTask
placesTask.execute(sb.toString());
}
Try with an emulator. I emulated my position with Genymotion, but it was quite long to install and setup everything.
You might first try to emulate your position with the official emulator, as it seems to be possible now. Check this out.

Is there a way to show road directions in Google Map API v2? [duplicate]

This question already has answers here:
Get driving directions using Google Maps API v2
(4 answers)
Closed 3 years ago.
I was looking for an answer using Google and here, and the only relevant posts I have found are:
Google Maps Android V2 and Direction API
Get driving directions using Google Maps API v2
but there is no answer there. So I have already mentioned it but I will say that again. I am looking for a solution for the Google Map API v2 using FragmentActivity and a SupportMagFragment and LatLng objects and not using MapView ,MapActivity and GeoPoint.
In addition I don't have the Overlay object to use so I can't paint the direction on the map, is there an alternative for that?
So is there a way to do that?
Try this solution here. You can get driving or walking direction on V2.
The Overlay is indeed something to forget.
Polylines can easily be drawn
https://developers.google.com/maps/documentation/android/lines#add_a_polyline
Just loop through yourr points after you parsed tjhe JSON response:
PolylineOptions rectOptions = new PolylineOptions()
.add(new LatLng(37.35, -122.0))
.add(new LatLng(37.45, -122.0)) // North of the previous point, but at the same longitude
.add(new LatLng(37.45, -122.2)) // Same latitude, and 30km to the west
.add(new LatLng(37.35, -122.2)) // Same longitude, and 16km to the south
.add(new LatLng(37.35, -122.0)); // Closes the polyline.
// Set the rectangle's color to red
rectOptions.color(Color.RED);
// Get back the mutable Polyline
Polyline polyline = myMap.addPolyline(rectOptions);
Your question title is much more general than your requirements, so I will answer this in a way that I think will benefit those viewing this question and hopefully meet your requirements in perhaps a different way.
If you are not showing directions in the context of a map already being a loaded fragment and something having been done to show directions over the map (which is probably similar to what the OP is doing), it's easier and I believe standard to do this with an Intent.
This launches a map pathing activity (through a separate application - where the app launched depends on the user's compatible apps, which by default is Google Maps) that plots directions from the origin address (String originAddress) to the
destination address (String destinationAddress) via roadways:
// Build the URI query string.
String uriPath = "https://www.google.com/maps/dir/";
// Format parameters according to documentation at:
// https://developers.google.com/maps/documentation/directions/intro
String uriParams =
"?api=1" +
"&origin=" + originAddress.replace(" ", "+")
.replace(",", "") +
"&destination=" + destinationAddress.replace(" ", "+")
.replace(",", "") +
"&travelmode=driving";
Uri queryURI = Uri.parse(uriPath + uriParams);
// Open the map.
Intent intent = new Intent(Intent.ACTION_VIEW, queryURI);
startActivity(activity, intent, null);
(Where activity is simply the currently active Activity - obtained through whatever means are appropriate in the current programming context).
The following code gets an address String from a LatLng object (which must then be processed for the URI query String as above):
/**
* Retrieves an address `String` from a `LatLng` object.
*/
private void getAddressFromLocation(
final StringBuilder address, final LatLng latlng) {
// Create the URI query String.
String uriPath =
"https://maps.googleapis.com/maps/api/geocode/json";
String uriParams =
"?latlng=" + String.format("%f,%f",
latlng.latitude, latlng.longitude) +
"&key=" + GOOGLE_MAPS_WEB_API_KEY;
String uriString = uriPath + uriParams;
// Issue the query using the Volley library for networking.
RequestFuture<JSONObject> future = RequestFuture.newFuture();
JSONObject response = null;
// Required for JsonObjectRequest, but not important here.
Map<String, String> jsonParams = new HashMap<String, String>();
JsonObjectRequest request =
new JsonObjectRequest(Request.Method.POST,
uriString,
new JSONObject(jsonParams),
new Response.Listener<JSONObject>() {
#Override
public void onResponse(JSONObject response) {
try {
if (response != null) {
String resultString =
response.getJSONArray("results")
.getJSONObject(0)
.getString("formatted_address");
// Assumes `address` was empty.
address.append(resultString);
} // end of if
// No response was received.
} catch (JSONException e) {
// Most likely, an assumption about the JSON
// structure was invalid.
e.printStackTrace();
}
} // end of `onResponse()`
}, // end of `new Response.Listener<JSONObject>()`
new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
Log.e(LOG_TAG, "Error occurred ", error);
}
});
// Add the request to the request queue.
// `VolleyRequestQueue` is a singleton containing
// an instance of a Volley `RequestQueue`.
VolleyRequestQueue.getInstance(activity)
.addToRequestQueue(request);
}
This request is asynchronous, but it can be made synchronous.
You will need to call toString() on the actual parameter passed to address to obtain originAddress.
Q:I was looking for an answer using Google and here, and the only
relevant posts i have found are: Google Maps Android V2 and Direction
API Google map API v2 - get driving directions
Answer: Your saying, "but there is no answer there." is not absolutely right. In this site, you can find just only a few clues about that. I think you will not get the perfect code and concrete implement KNOW-HOWs here. In fact, many developers want to make the app to display the routing or directions on Google Maps. But I think there is no solution to get directions just only with the pure Google Maps API v2.
Q: So I have already mentioned it but I will say that again. I am
looking for a solution for the Google Map API v2 using
FragmentActivity and a SupportMagFragment and LatLng objects and not
using MapView ,MapActivtiy and GeoPoint.
Answer: Here are a few good sample tutorials (click here). You can find what you want.
Q: In addition i don't have the Overlay object to use so i can't paint
the direction on the map, is there an alternative for that? So is
there a way to do that?
Answer: In the Google Maps API v2, the annoying Overlay and so on are not any more required. For this, you can find the answer in my linked site above.

Connect GeoPoints Android

I have an Android application and I'm trying to populate a Google Map with a route, this route is store on a JSON array this way:
JSONArray.getString("points") = ["-33.45591917507404, -70.59198361376951","-33.453484420618416, -70.61635952929686"]
So in this case I have
Point A=(-33.49088437162095, -70.64043194102163) and
Point B=(-33.49423964397045, -70.63992768572683)
And my route or path is A-----B
I'm new to Android and I was wondering how to get this to work. Also, in this case my route is A-----B, but it can also be A----B----C----D. I can have any number of points on the path.
One thing you can try is the Google Maps Polyline object: https://developers.google.com/maps/documentation/javascript/reference#Polyline You specify to setPath() an ordered list of the points (either an Array of LatLng or an MVCArray or LatLng), you want to connect together on the map, and Google Maps will make a polyline for you to your specifications.
// path = Array of LatLng or MVCArray of LatLng
routeLine = new Polyline();
routeLine.setPath(JSONArray);
In your case, passing JSONArray into setPath should work OK.
If you want to get fancy and incorporate directions, you need to use the Google Directions API. https://developers.google.com/maps/documentation/javascript/directions
// All waypoints must be stopovers for the Directions service to optimize their route.
// start & end are of type String or LatLng, waypts is an array of String or LatLng
request = {
origin: start,
destination: end,
waypoints: waypts,
optimizeWaypoints: [type Boolean],
travelMode: [type TravelMode]
};
// go on and actually perform the request
directionsService.route(request, function(result, status) {
if (status == google.maps.DirectionsStatus.OK) {
// if successful, this will run
}
});
Once you finish constructing your object, you should be able to display it by running setMap(map:Map), such as
routeLine.setMap(map)

Unity3d Input.location from documentation not available in code

I am working on a Unity3d for Android project. Using the documentation from Unity:
http://unity3d.com/support/documentation/ScriptReference/Input-location.html
I should be able to use Input.location to get access to GPS location data. But instead I get an error basically telling me the Input.location is not part of Unity.
Assets/Scripts/Prototype1.js(27,29): BCE0019: 'location' is not a
member of 'UnityEngine.Input'.
I've checked for updates and it tells me the system is fully up to date. I'm running version 3.4.2f3
Is the documentation outdated? Is there a different reference to the LocationService? How can I get the location data?
The files at unity3d.com contain the documentation for the most recent release Unity3D 3.5. If you look at your documentation in the local file system you won't find Input.location. Seems like they have changed the interface in Unity3D 3.5.
I haven't used GPS until now, maybe this thread and the links provided can throw some light on this:
How to import GPS location coordinates from Android device?
I found documentation to the old code, based in iPhoneSettings. This is the code I'm using now, it's not complete (doesn't respond to time out of the location service and other such well rounded behavior), but demonstrates the code.
function Start () {
locationStatus = LocationServiceStatus.Stopped;
StartCoroutine(startLocationService());
}
function Update () {
if(locationStatus == LocationServiceStatus.Running)
{
/*
lat = Input.location.latitude;
lon = Input.location.longitude;
alt = Input.location.altitude;
*/
lat = iPhoneInput.lastLocation.latitude;
lon = iPhoneInput.lastLocation.longitude;
alt = iPhoneInput.lastLocation.altitude;
}
}
function startLocationService()
{
//Input.location.Start(accuracy, distance);
iPhoneSettings.StartLocationServiceUpdates(accuracy, distance);
//while(Input.location.status == LocationServiceStatus.Initializing && maxWait > 0) {
while(iPhoneSettings.locationServiceStatus == LocationServiceStatus.Initializing && maxWait > 0)
{
yield WaitForSeconds(1);
maxWait--;
}
//locationStatus = Input.location.status;
locationStatus = iPhoneSettings.locationServiceStatus;
}

Categories

Resources