Issue
I want to show google maps in tabbed layout
So I created a viewPager in main activity and added below fragment for map
But it is showing up empty.
Every overridden function is getting called as expected.
I am not able to understand what exactly is causing map to not show up.
Below is my code
fragment_map.xml
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.gms.maps.MapView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:apiKey="@string/google_maps_key"
android:id="@+id/mapView" >
</com.google.android.gms.maps.MapView>
MapFragment.java
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapView;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
import com.i2e1.iconnect.R;
import java.util.ArrayList;
import java.util.List;
public class MapFragment extends Fragment implements OnMapReadyCallback {
MapView m;
GoogleMap googleMap;
private List<MarkerOptions> markers;
public MapFragment() {
// Required empty public constructor
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_map, container, false);
m = (MapView) v.findViewById(R.id.mapView);
m.getMapAsync(this);
m.onCreate(savedInstanceState);
return v;
}
@Override
public void onResume() {
super.onResume();
m.onResume();
}
@Override
public void onPause() {
super.onPause();
m.onPause();
}
@Override
public void onDestroy() {
super.onDestroy();
m.onDestroy();
}
@Override
public void onLowMemory() {
super.onLowMemory();
m.onLowMemory();
}
@Override
public void onMapReady(GoogleMap googleMap) {
this.googleMap = googleMap;
for (MarkerOptions m : markers) {
googleMap.addMarker(new MarkerOptions()
.position(m.getPosition())
.title(m.getTitle()));
}
googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(markers.get(0).getPosition(), 15), 5000, null);
m.onResume();
}
}
Solution
Sorry Guys
It was a simple problem. I just factory reset a device to test and it was never connected to WIFI/mobile data before launching app.
Problem got resolved just after connecting to wifi.
Answered By - Ravi Sahu
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.