What I am trying to do: fetch data using google map api, then pass data to the next screen.
What's wrong: it works fine on iOS simulator, it manages to get to the next screen and populate the map with the data (prints position, "yay", http status code, and the "loopyays"). But on android emulator, it prints only position and "yay", and hangs there, does not navigate to the next screen.
What went wrong? :/ Please help me out..
class _LoadingScreenState extends State<LoadingScreen> {
void getUserLocation() async {
try {
Position position = await Geolocator()
.getCurrentPosition(desiredAccuracy: LocationAccuracy.high);
print(position);
Set<Marker> markers = {};
String url =
'https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=${position.latitude},${position.longitude}&maxprice=4&radius=1500&type=restaurant&keyword=cruise&key=AIzaSyDVzxxxxxxxxxxxxxxxxxxx';
print('yay');
http.Response data = await http.get(url);
print(data.statusCode);
var resultList = jsonDecode(data.body)['results'];
for (Map i in resultList) {
var coords = (i['geometry']['location']);
print('loopyay');
markers.add(Marker(
markerId: MarkerId(i['name']),
position: LatLng(coords['lat'], coords['lng'])));
}
Navigator.push(context, MaterialPageRoute(builder: (context) {
return UserLocationScreen(
userLocation: position,
markers: markers,
);
}));
} catch (e) {
print(e);
}
}
my config
- I have
androidmapsdk
activated on my google console - in my androidmanifest I have this after the
< meta-data android:name="com.google.android.geo.API_KEY"
android:value="AIzaSyDVzbjC2hViOnxxxxxxxxxx"/>
- in my build.gradle
dependencies {
classpath 'com.android.tools.build:gradle:3.3.1'
classpath 'com.google.gms:google-services:4.2.0'
}
- in my gradle.properties
android.enableJetifier=true
android.useAndroidX=true
org.gradle.jvmargs=-Xmx1536M