Reputation: 553
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
androidmapsdk
activated on my google console< meta-data android:name="com.google.android.geo.API_KEY"
android:value="AIzaSyDVzbjC2hViOnxxxxxxxxxx"/>
dependencies {
classpath 'com.android.tools.build:gradle:3.3.1'
classpath 'com.google.gms:google-services:4.2.0'
}
android.enableJetifier=true
android.useAndroidX=true
org.gradle.jvmargs=-Xmx1536M
Upvotes: 1
Views: 800
Reputation: 836
In Android 9 pie, http request is not permitted in default.
Solution:
Please update this in your AndroidManifest.xml
file like below.
<application
...
android:usesCleartextTraffic="true">
... // Your current code.
</application>
Have a good day.
Upvotes: 5