public class Fragment1 extends Fragment{
private GoogleMap mMap; // Might be null if Google Play services APK is not available.
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_1, container, false);
}
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
setUpMapIfNeeded();
super.onViewCreated(view, savedInstanceState);
}
private void setUpMapIfNeeded() {
// Do a null check to confirm that we have not already instantiated the map.
if (mMap == null) {
// Try to obtain the map from the SupportMapFragment.
mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
// Check if we were successful in obtaining the map.
if (mMap != null) {
setUpMap();
}
}
}
private void setUpMap() {// выводим значок своего местоположения
mMap.setMyLocationEnabled(true);//выводим индикатор своего местоположения
mMap.addMarker(new MarkerOptions().position(new LatLng(0, 0)).title("Marker"));
}
}
public class Fragment1 extends Fragment{
private GoogleMap mMap;
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_1, container, false);
return v;
}
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
setUpMapIfNeeded();
}
private void setUpMapIfNeeded() {
// Do a null check to confirm that we have not already instantiated the map.
if (mMap == null) {
// Try to obtain the map from the SupportMapFragment.
mMap = ((SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.map1))
.getMap();
// Check if we were successful in obtaining the map.
if (mMap != null) {
setUpMap();
}
}
}
private void setUpMap() {
mMap.setMyLocationEnabled(true);//выводим индикатор своего местоположения
}
}
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<fragment
android:id="@+id/map1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="3dp"
android:layout_weight="2"
android:name="com.google.android.gms.maps.SupportMapFragment" />
</LinearLayout>
MapView m;
GoogleMap map;
try {
MapsInitializer.initialize(getActivity());
m = (MapView) v.findViewById(R.id.mapView);
m.onCreate(savedInstanceState);
extraMarkerInfo = new HashMap<String, HashMap>();
if (location!=null) {
pos = new LatLng(location.getLatitude(), location.getLongitude());
}
map = m.getMap();
} catch (Exception e) {
e.printStackTrace();
}
Marker marker = map.addMarker(new MarkerOptions().position(positions)
.icon(BitmapDescriptorFactory.fromBitmap(imageLoader.getCircleBitmap(image, context)))
.flat(false)
.title(name+" , "+user_age)
.snippet(venue_name)
.anchor(0.5f, 1));