I am making an android app where it will collect the overview_polyline->points string from the google maps api. For testing sake i have directly copied it(overview_polyline->points) and used as shown in the below code. I am using Polyutil to decode it:
List<LatLng> list = PolyUtil.decode("yxkpA_sjgMoAXuA#{GHeAFo#Jg#P[FcDHiCFu#B}#DkATiAFi#Hw#FcAKmAA[zG#n#DjAFpAPhB`#vBRt#`#|#dAbCg#F{B?eA?BpAAjC?vAC^W|#Ir#GdBe#hCm#lDpCl#|D~#J#?`AHdEAxGAVGZe#jBOnBzDLnGWPDFNRjDAjAG~#S|CCn#v#BXF?`#LtBEHOESC[BKBIJWWA?#?VV?PDbACJB?d#Ix#MRhBANABXRNDx#BBD#VD#FAj#?NB|#HAZLtBAf#CR");
I got the string from the below google direction api result:
"overview_polyline" : {
"points" : "yxkpA_sjgMoAXuA#{GHeAFo#Jg#P[FcDHiCFu#B}#DkATiAFi#Hw#FcAKmAA[zG#n#DjAFpAPhB`#vBRt#`#|#dAbCg#F{B?eA?BpAAjC?vAC^W|#Ir#GdBe#hCm#lDpCl#|D~#J#?`AHdEAxGAVGZe#jBOnBzDLnGWPDFNRjDAjAG~#S|CCn#v#BXF?`#LtBEHOESC[BKBIJWWA?#?VV?PDbACJB?d#Ix#MRhBANABXRNDx#BBD#VD#FAj#?NB|#HAZLtBAf#CR"
},
When i run the app it says java.lang.StringIndexOutOfBoundsException: length=268; index=268
Related
I have apps which using google maps. iOS has GoogleMaps=6.2.1, android has:
implementation 'com.google.android.gms:play-services-maps:18.0.2'
implementation 'com.google.maps.android:android-maps-utils:2.2.3'
On both devices maps works good, but i faced with problem related with Point Of Interested id, and i cant find information why it happens.
So, for example, in iOS i have listener which return information about clicked place:
func mapView(_ mapView: GMSMapView, didTapPOIWithPlaceID placeID: String, name: String, location: CLLocationCoordinate2D) {
// placeID will be ZhDJA-k2Ym_pPkcFG1VfPvb99Vv, good ID
}
Example in Android, android has also listener, which return information about clicked place:
override fun onPoiClick(poi: PointOfInterest) {
// poi.placeId - will be like ZhDJAAAAAAAAAAA1VfPvb99Vv, bad ID
}
I clicked in the same place in iOS and Android, but android in some reason replace part of placeId to AAAAAAA.
but if in Android i will do additional request
placesClient.fetchPlace("ZhDJAAAAAAAAAAA1VfPvb99Vv", listOf(Place.Field.ID))
.addOnSuccessListener { response: FetchPlaceResponse ->
// response.place.id - now it ZhDJA-k2Ym_pPkcFG1VfPvb99Vv like in iOS without any additional requests
}
I will get normal placeID which in iOS i have without additional requests.
Why Google Map in Android and Google Map on iOS returns different placeID ?
I'm trying to use the Google Cloud Translation API in my application but whenever I try to translate something it comes up with this missing valid API error.
I've done the quickstart steps and that didn't work.
I've tried the steps in the client library authentication and that hasn't worked either.
E/AndroidRuntime: FATAL EXCEPTION: main
Process: herrsa1.bit.translator, PID: 16598
com.google.cloud.translate.TranslateException: The request is missing a valid API key.
at com.google.cloud.translate.spi.v2.HttpTranslateRpc.translate(HttpTranslateRpc.java:61)
.. 18 more
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
Caused by: com.google.api.client.googleapis.json.GoogleJsonResponseException: 403 Forbidden
{
"code" : 403,
"errors" : [{
"domain" : "global",
"message" : "The request is missing a valid API key.",
"reason" : "forbidden"
}],
"message" : "The request is missing a valid API key.",
"status" : "PERMISSION_DENIED"
}
at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:113)
... 4 more
at com.google.cloud.translate.spi.v2.HttpTranslateRpc.translate(HttpTranslateRpc.java:130)
... 19 more
If you are using client library and you have already downloaded your service account json file, try doing this:
// Instantiates a client
const translate = new Translate({
projectId: 'your project id', //eg my-proj-0o0o0o0o'
keyFilename: 'path of your service acount json file' //eg my-proj-0fwewexyz.json
});
instead of this:
// Instantiates a client
const translate = new Translate({projectId});
This way you need only your the service acount json file and the specific API enabled
The error on API key means you didn't create or use the key properly. You need to do the following for the key to work:
Create a service account
Create a key for above service account
Download the key to a location, for example, a local path
Set the environment variable GOOGLE_APPLICATION_CREDENTIALS to the file path of the key, refer to samples in Quickstart tutorial
I'd reccomend doing #1 & #2 in GCP Console, and handling #3 & #4 in Cloud Shell.
The key your using does not have the permission to use Translate APIs.
To fix this :
Go to Google Cloud Platform console
Chose your project from the drop down menu in the top bar
Go to API & Services > Library
Search for Cloud Translation API and click on it
Enable it
Go to API & Services > Credentials
Select the key you are using in your Android App
From the menu called Restrict key, choose Cloud Translation API
Save your edit
Now the APIs will work properly.
I also tried to execute this sample program.
I followed the same instruction. But when I executing I got same error(The request is missing a valid API key).
I changed a line in the sample program.
Instead of
Translate translate = TranslateOptions.getDefaultInstance().getService();
I added
Translate translate = TranslateOptions
.newBuilder()
.setCredentials(
ServiceAccountCredentials
.fromStream(new FileInputStream(
"YourCredentialFilePath.json")))
.build().getService();
Now it is working.
Sample code after fix.
// Imports the Google Cloud client library
import java.io.FileInputStream;
import com.google.auth.oauth2.ServiceAccountCredentials;
import com.google.cloud.translate.Translate;
import com.google.cloud.translate.Translate.TranslateOption;
import com.google.cloud.translate.TranslateOptions;
import com.google.cloud.translate.Translation;
public class QuickstartSample {
public static void main(String... args) throws Exception {
//Instantiates a client
//Removed next line
//Translate translate = TranslateOptions.getDefaultInstance().getService();
//Added this line
Translate translate = TranslateOptions
.newBuilder()
.setCredentials(
ServiceAccountCredentials
.fromStream(new FileInputStream(
"YourCredentialFilePath.json")))
.build().getService();
//The text to translate
String text = "Hello, world!";
//Translates some text into Russian
Translation translation =
translate.translate(
text,
TranslateOption.sourceLanguage("en"),
TranslateOption.targetLanguage("ru"));
System.out.printf("Text: %s%n", text);
System.out.printf("Translation: %s%n", translation.getTranslatedText());
}
}
I am using Ionic 2.2.3 for building hybrid mobile app. I am using Cordova Google Map plugin for plotting some points on google map. Same code base is working for all android devices fine but when I try to plot polyline in iOS(any device), the app gets crashed.
I am getting the points in below format -
{"lat":22.51,"lng":88.26},{"lat":22.549092,"lng":88.284892}
and then add the points to map -
map.addPolyline({
'points': points,
'color': "#DAA520",
'width': 6,
'name': '<line Name>'
}, function (polyline) {
polyline.on(plugin.google.maps.event.POLYLINE_CLICK, function (latlng) {
map.addMarker({
position: latlng,
}, function (marker) {
//some code to show the line details when clicked
});
});
});
When I run the same code in emulator, there are no issues and app runs fine. I guess there is some memory issue and I am struggling with same.
Yes. After checking some points I found out that it is breaking after few 100 points. So I am querying now some 100 points and rest based on user's query.
I try to get Map route between two places in android and i refered this Link, here
but its showing error at this two places,
HttpClient oHttp = HttpClient.getInterfaces();
String szXml = oHttp.doGet(szUrl,"");
how to solve this
This is a question about Mapquest Android Maps API.
Does anyone know that the createRoute method is supporting lat/Lng or not in mapquest?
public void createRoute(java.lang.String from, java.lang.String to)
The document I found here:
I have read the "Location Format Documentation" : link
It seems that createRoute method supports lat/Lng.
I tried to input lat/Lng a whole day but it returns me an error message only:
Unable to create route.
Error: -1"
Message:[null]
Are you still seeing this error message? The MapQuest Android Maps API does support lat/lng input for routing. Here is a sample request that uses lat/lng inputs:
private void displayRoute() {
RouteManager routeManager= new
RouteManager( this );
routeManager.setMapView( map );
routeManager.createRoute( "{latLng:{lat:37.765007,lng:-122.239937}}" , "Fremont, CA" );
}
Also, The MapQuest Developer Network has an Android Maps API forum. It is also a good resource to check!
You can write like this
RouteManager routeManager = new RouteManager(this);
routeManager.setMapView(map);
routeManager.createRoute("37.002004,35.322998", "36.802687,34.632812");
or like this
RouteManager routeManager = new RouteManager(this);
routeManager.setMapView(map);
routeManager.createRoute("Any City Name", "Any City Name");
MapQuest is supporting this types