我一直在遵循一个循序渐进的教程,试图使用Mapbox和Android Studio使用"Android上的跟踪设备位置"教程创建地图,但遇到了一个似乎没有在Mapbox上列出的问题。在教程的"倾听更新"部分,代码的第176行写道:
Toast.makeText(activity, String.format(activity.getString(R.string.new_location)
new_location显示为红色,并且事先未定义。有人知道怎么解决这个问题吗?
https://docs.mapbox.com/help/tutorials/android-location-listening/#listen-到位置更新
如果你想让它运行,你必须遵循Ryan的建议(注释(,并将他从Mapbox的activity_strings.xml突出显示的字符串添加到你的字符串.xml中。
<string name="new_location">New lat: %1$s New longitude: %2$s</string>
%%1$s将用您在中传递的第一个参数填充,%2$s将用您传递的第二个参数填充
String.format(activity.getString(R.string.new_location),
String.valueOf(result.getLastLocation().getLatitude()),
String.valueOf(result.getLastLocation().getLongitude()))