Skip to content

Instantly share code, notes, and snippets.

View mizutori's full-sized avatar

Takamitsu Mizutori mizutori

View GitHub Profile
private fun drawLocationAccuracyCircle(location: Location) {
if (location.accuracy < 0) {
return
}
val latLng = LatLng(location.latitude, location.longitude)
locationAccuracyCircle?.let{
it.center = latLng
} ?: run{
override fun onLocationChanged(newLocation: Location?) {
newLocation?.let{
Log.d(LOG_TAG, "(" + it.latitude + "," + it.longitude + ")")
gpsCount++
if (isLogging) {
locationList.add(newLocation);
}
@NeedsPermission(Manifest.permission.ACCESS_FINE_LOCATION)
fun setupGoogleMap(googleMap: GoogleMap) {
map = googleMap
map.uiSettings.isZoomControlsEnabled = false
map.isMyLocationEnabled = false //TODO: RuntimePermissionを後で入れる
map.uiSettings.isCompassEnabled = true
map.uiSettings.isMyLocationButtonEnabled = true
map.setOnCameraMoveStartedListener { reason ->
if (reason == GoogleMap.OnCameraMoveStartedListener.REASON_GESTURE) {
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment
android:layout_width="match_parent"
val gpsFreqInMillis = 5000
val gpsFreqInDistance = 5 // in meters
locationManager.addGpsStatusListener(this)
locationManager.requestLocationUpdates(
gpsFreqInMillis.toLong(),
gpsFreqInDistance.toFloat(),
criteria,
this,
val criteria = Criteria()
criteria.accuracy =
Criteria.ACCURACY_FINE //setAccuracyは内部では、https://stackoverflow.com/a/17874592/1709287の用にHorizontalAccuracyの設定に変換されている。
criteria.powerRequirement = Criteria.POWER_HIGH
criteria.isAltitudeRequired = false
criteria.isSpeedRequired = true
criteria.isCostAllowed = true
criteria.isBearingRequired = false
//API level 9 and up
@mizutori
mizutori / gist:fa4eabb621bdbcd430a403bf02743dac
Created January 5, 2019 09:43
AndroidLocationStarterKitKotlin_MainActivity_Initial
class MainActivity : AppCompatActivity() {
var locationService: LocationService? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val locationService = Intent(this.application, LocationService::class.java)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
def process_event(event):
if event.type == EventType.ON_CONVERSATION_TURN_STARTED:
print()
print(event)
if (event.type == EventType.ON_CONVERSATION_TURN_FINISHED and
event.args and not event.args['with_follow_on_turn']):
print()
if event.type == EventType.ON_DEVICE_ACTION:
"fulfillment": {
"staticFulfillment": {
"templatedResponse": {
"items": [
{
"simpleResponse": {
"textToSpeech": "Move for $number seconds"
}
},
{
"types": [
{
"name": "$Speed",
"entities": [
{
"key": "SLOWLY",
"synonyms": [
"slowly",
"slow"
]