Android issue with Skobbler SDK for offline geocoding - android

I implemented Skobbler SDK in my app to navigate offline maps. I have an issue while trying to get coordinates from an address when user is offline. Even if I have installed the package relative to the city in which I am trying to navigate, when I start multi-step search it returns empty results without the possibility to understand what I am doing wrong because there is no way to manage eventual error messages. Here is my code as reported in Skobbler docs:
private void searchAtCurrentLevel(long parentId, SKSearchManager.SKListLevel level) {
// get a search manager object
SKSearchManager mgr = new SKSearchManager(this);
// get a multi-step search object
SKMultiStepSearchSettings searchSettings = new SKMultiStepSearchSettings();
// set the offline package in which to search
searchSettings.setOfflinePackageCode(code);
// set list level of the search
searchSettings.setListLevel(level);
// set maximum number of results to be received
searchSettings.setMaxSearchResultsNumber(20);
// set the id of the parent in which to search
searchSettings.setParentIndex(parentId);
// set a filter for the results
searchSettings.setSearchTerm("");
// initiate the search
mgr.multistepSearch(searchSettings);
}
where "code" is relative to the code of the city that I am into (for example GBCITY04 for London) and parentId is -1 like shown in Skobbler's Android "How To". I also tried to enter all different listLevel values but nothing changed.
In my app, I avoided to download "Maps.json" file because I have to manage only 2 cities, Milan and London, so i download only Milan and London's maps having relative city codes (ITCITY01 and GBCITY04). Can this be the cause of my problems?
Thanks in advance for the support.

Related

Iterating over a List with multiple Place AddressComponents - Kotlin

I am receiving a Place Detail (from Google Maps SDK Android) from a specific place.
This Place has different Place Details as a Result.
The output is the following:
Place found: AddressComponents{asList=[AddressComponent{name=58, shortName=58, types=[street_number]}, AddressComponent{name=Schwertstraße, shortName=Schwertstraße, types=[route]}, AddressComponent{name=Sindelfingen, shortName=Sindelfingen, types=[locality, political]}, AddressComponent{name=Böblingen, shortName=BB, types=[administrative_area_level_3, political]}, AddressComponent{name=Stuttgart, shortName=Süd, types=[administrative_area_level_2, political]}, **AddressComponent{name=Baden-Württemberg, shortName=BW, types=[administrative_area_level_1, political]}**, AddressComponent{name=Deutschland, shortName=DE, types=[country, political]}, AddressComponent{name=71065, shortName=71065, types=[postal_code]}]}
I am looking for the specific information of the typ=administrative_area_level_1 and level_2.
But i am not able to find a way of iteration.
With Kotlin i am able to access values hard, but this is not the solution.
The Objects AddressComponent change their posisitions in new requests to Google Place API. Even some places do only provide less information.
System.out.println(place.addressComponents?.asList()?.get(5)?.name)
System.out.println(place.addressComponents?.asList()?.get(5)?.shortName)
Results in:
Baden-Württemberg
BW
So how can i access the PlaceResult without hard-coding the positions, ignoring the order and find the specific information i am looking for?
The functionality that you're looking for is collections filtering. Assuming your list is named place, the following will return the two matching rows:
val desiredTypes = setOf("administrative_area_level_1",
"administrative_area_level_2")
println(place.filter { it.types.any(desiredTypes::contains) } )
// Prints: [name=Stuttgart, shortName=Süd, types=[administrative_area_level_2, political], name=Baden--Württemberg, shortName=BW, types=[administrative_area_level_1, political]]
The filter function returns any matching elements. it is the (default) name of the element under consideration. The any function returns whether the types sub-element for each element contains any of the items in the desiredTypes set.

Retrieving data from firebase to google maps

I am making an app which downloads LatLngs from firebase and shows them as markers in google maps API, users can add new LatLngs.
In my database I also have the pricepoint and types of markers. In the main screen the user can choose what types of marker he wants to see on the map.
So my application does something like this:
locations.orderByChild(pricepoint).equalTo(choosenPricepoint);
and then I check programmatically if types match those chosen by the user
int type = Integer.parseInt(locations.child("restaurantType").getValue().toString();
if(type == funCode|| type == runingCode|| type == sportsCode
{
mMap.addMarker(new MarkerOptions().position(snapshot.getLatlng);
}
And it works fine with 250 records, but I'm expecting over 10,000 of them in my database so I am worried that it will be too slow.
I don't know if showing markers only where user's maps camera is and deleting other will be faster. What do you suggest?
You can use GeoFire , a firebase library that uses GeoHashes to merge lat+lon into a single property.That way you can do the distance filtering directly on the database.
You should have 2 entries in firebase database,one for setting your object location and one for setting your object with its fields.
As you can see they have the same id.So first you are queriing for nearby object by GeoFire in geo_data entry,and you will get the ids of the object which are nearby,then you can retreive object with its properties directly from database using the ids in my case in user_data entry

Retrieve places by type from android maps api

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!

Android Square Register API: ILLEGAL_LOCATION_ID

I am integrating Square into my Android app.
I am struggling with where to find the locationId to pass to the enforceBusinessLocation() method. I've set up a location in my Square dashboard but it isn't obvious where to get the locationId from.
I've tried using the location nickname (I tried both mixed case and uppercase - so, in my case, "mwe" and "MWE"), but that didn't work. It results in:
ILLEGAL_LOCATION_ID: The LOCATION_ID parameter does not match the ID
of the business location currently logged in to Square Register.
I have selected that same location when logging into the Square Register app on the device.
I understand the locationId is optional, but I would like to include it.
So where to find the locationId as required for enforceBusinessLocation()?
You can get your locations with the /v1/me/locations or /v2/locations endpoints.
https://docs.connect.squareup.com/api/connect/v2/#endpoint-listlocations
https://docs.connect.squareup.com/api/connect/v1/#get-locations
There is a much easier way to get it. Just log in and click on Accounts & Settings, click on Locations (here's a shortcut), click the location and then you can see URL of the page change. The location ID is the last part of the URL.

How to get the nearest city from google place api (android) based on a given latitude and longitude

I am getting a latitude and longitude from GPS and want to search the nearest city from my current location.
Currently I'm sending a request to Google Places with types like "neighborhood|locality", but this does not return any nearest city. Even if I only specify "neighborhood" or "locality" by themselves, I still get no results. However if I use a type like "bar" then it returns a list of bars.
I'm using the types listed here:
https://developers.google.com/places/documentation/supported_types
Can anybody tell me what Place Type I should use to get the nearest city or places, or how I can otherwise get the nearest city?
Are you getting back a results array with nothing in it, or simply getting nothing back? The docs say you'll get a results array "even if the service returns no results". Is it possible that the city you're searching contains bars but does not contain anything classified as a "neighborhood" or a "locality"?
This question says
you can restrict the results that will come back in the Autocomplete
to addresses by setting types to 'geocode' ... you can restrict the
results that come back in the Autocomplete to cities by setting types
to 'cities'
If you're just trying to get the city name, rather than searching for something inside the city, perhaps you want to use one of those options?

Categories

Resources