सूचना प्राप्त करें जियोकोडर इस्तेमाल के लिए तैयार है

वोट
-1

मैं एक का उपयोग करके उपकरण की कनेक्टिविटी को देख रहा हूँ BroadcastReceiver। डिवाइस ऑनलाइन करने के लिए ऑफ़लाइन से अपने राज्य बदलता है, तो मैं नीचे दिए गए कोड में जैसे कुछ जियोकोडिंग प्रदर्शन करने की जरूरत है।

समस्या यह है, कि जियोकोडिंग के साथ विफल: java.io.IOException: grpc failed
कॉल किसी भी तरह (जैसे एक ब्रेकपाइंट के कारण) में देरी हो जाती है तो जियोकोडर ठीक से काम करने लगता है।

वहाँ एक रास्ता सूचना पाने के लिए जब है android.location.Geocoderका उपयोग करने के लिए तैयार है?

// in BroadcastReceiver:

init {
    context.registerReceiver(this, IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION))
}


override fun onReceive(context: Context?, intent: Intent?) {
    context?.let {
        val activeNetworkInfo = (context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager).activeNetworkInfo
        val isConnected = activeNetworkInfo != null && activeNetworkInfo.isConnected

        // if `isConnected` geocoding gets triggered
    }
}

// Geocoding
var coordinate: LatLng? = null

val address = arrayOf(
    location.street, location.streetNumber,
    location.zipCode, location.city,
    location.country
).joinToString( )

try {
    val geocoder = Geocoder(context)
    geocoder.getFromLocationName(address, 1).firstOrNull()?.let { result ->
        coordinate = LatLng(result.latitude, result.longitude)
    }
} catch (a: IOException) {
    coordinate = null
}

// do something with `coordinate`
29/05/2018 को 12:26
का स्रोत उपयोगकर्ता
अन्य भाषाओं में...                            


1 जवाब

सूचना प्राप्त करें जियोकोडर इस्तेमाल के लिए तैयार है

वोट
-1

मैं एक का उपयोग करके उपकरण की कनेक्टिविटी को देख रहा हूँ BroadcastReceiver। डिवाइस ऑनलाइन करने के लिए ऑफ़लाइन से अपने राज्य बदलता है, तो मैं नीचे दिए गए कोड में जैसे कुछ जियोकोडिंग प्रदर्शन करने की जरूरत है।

समस्या यह है, कि जियोकोडिंग के साथ विफल: java.io.IOException: grpc failed
कॉल किसी भी तरह (जैसे एक ब्रेकपाइंट के कारण) में देरी हो जाती है तो जियोकोडर ठीक से काम करने लगता है।

वहाँ एक रास्ता सूचना पाने के लिए जब है android.location.Geocoderका उपयोग करने के लिए तैयार है?

// in BroadcastReceiver:

init {
    context.registerReceiver(this, IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION))
}


override fun onReceive(context: Context?, intent: Intent?) {
    context?.let {
        val activeNetworkInfo = (context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager).activeNetworkInfo
        val isConnected = activeNetworkInfo != null && activeNetworkInfo.isConnected

        // if `isConnected` geocoding gets triggered
    }
}

// Geocoding
var coordinate: LatLng? = null

val address = arrayOf(
    location.street, location.streetNumber,
    location.zipCode, location.city,
    location.country
).joinToString(" ")

try {
    val geocoder = Geocoder(context)
    geocoder.getFromLocationName(address, 1).firstOrNull()?.let { result ->
        coordinate = LatLng(result.latitude, result.longitude)
    }
} catch (a: IOException) {
    coordinate = null
}

// do something with `coordinate`
29/05/2018 को 12:26
का स्रोत उपयोगकर्ता

Cookies help us deliver our services. By using our services, you agree to our use of cookies. Learn more