Created
June 18, 2019 03:36
-
-
Save ricardoogliari/10e1f61bd6c67f1f499fc16c9271f45b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MainActivity: FlutterActivity() { | |
private val CHANNEL_GEOLOCATOR = "geolocator" | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
GeneratedPluginRegistrant.registerWith(this) | |
MethodChannel(flutterView, CHANNEL_GEOLOCATOR).setMethodCallHandler( | |
object : MethodCallHandler { | |
override fun onMethodCall(call: MethodCall, result: MethodChannel.Result) { | |
val latitude: Double? = call.argument("latitude"); | |
val longitude: Double? = call.argument("longitude"); | |
if (latitude != null && longitude != null) { | |
result.success(getAddress(latitude, longitude)); | |
} else { | |
result.error("UNAVAILABLE", "Método não recebeu latitude e/ou longitude", null); | |
} | |
} | |
}) | |
} | |
fun getAddress(latitude: Double, longitude: Double): String{ | |
val geocoder: Geocoder = Geocoder(this) | |
val listAddress = geocoder.getFromLocation(latitude, longitude, 1) | |
val address = listAddress.get(0) | |
return address.getAddressLine(0) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment