-3

I've been following a step by step tutorial trying to create a map using Mapbox and Android Studio using the 'Tracking Device Location on Android" tutorial but have run into a problem that doesn't seem to be outlined on Mapbox. In the 'Listen to Updates' section of the tutorial, on line 176 of the code it reads:

Toast.makeText(activity, String.format(activity.getString(R.string.new_location)

new_location shows up in red and has not been defined beforehand. Does anyone know how to fix this?

https://docs.mapbox.com/help/tutorials/android-location-listening/#listen-to-location-updates

  • I tried that already and it gave this message: format string 'new_location' is not a valid format string so should not be passed as String. format – Jermaine Amissah Mar 30 '20 at 22:02
  • java basics ... find out how first string of `String.Format()` with 3 strings should looks like – Selvin Mar 30 '20 at 22:05
  • 1
    You should probably report this as a bug in the tutorial to Mapbox, seems like they forgot to tell you to get the strings they used: https://github.com/mapbox/mapbox-android-demo/blob/33620d29e2db98879fcd61e0dac3c867236b1876/MapboxAndroidDemo/src/main/res/values/activity_strings.xml#L46 – Ryan M Mar 30 '20 at 22:12

1 Answers1

0

If you want to get it running, you would have to follow Ryan's advice (comment) and add the string he has highlighted from Mapbox' activity_strings.xml into your strings.xml.

<string name="new_location">New lat: %1$s New longitude: %2$s</string>

%1$s will be populated with the first parameter you pass and %2$s with second parameter you pass in

String.format(activity.getString(R.string.new_location),
String.valueOf(result.getLastLocation().getLatitude()), 
String.valueOf(result.getLastLocation().getLongitude()))
Moritz
  • 1,710
  • 1
  • 8
  • 13