I've been trying to show some info whith info windows -in my app which uses google map- with InfoWindowAdapter but it just does'nt show any pictures so whats the problem?
here's my code for it
public class findonmap extends FragmentActivity implements OnMapReadyCallback {
private GoogleMap mMap;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
#Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
Bundle recevier=getIntent().getExtras();
float a=recevier.getFloat("x");
float b=recevier.getFloat("y");
LatLng mycordinate = new LatLng(a,b);
mMap.addMarker(new MarkerOptions().position(mycordinate).icon(BitmapDescriptorFactory.
fromResource(R.drawable.marker2)));
mMap.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() {
#Override
public View getInfoWindow(Marker marker) {
return null;
}
#Override
public View getInfoContents(Marker marker) {
// ConstraintLayout layout=(ConstraintLayout)findViewById(R.id.indo)
View view=getLayoutInflater().inflate(R.layout.info,null);
return view;
}
});
int zoomLevel = 4; //This goes up to 21
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(mycordinate, zoomLevel));
}}
Related
I've put some red marks over some places but I can not put texts over every place so that a different name and number is protected
As an example I want to type above each tag :
Grup_num + Index Number
Code:
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {
private GoogleMap mMap;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
#Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
mMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);
mMap.getUiSettings().setZoomControlsEnabled(true);
// Add a marker in Sydney and move the camera
// LatLng Muscat = new LatLng(23.5840481, 58.388295);
double[] myListl = {25.696042,25.696847,25.697214};
double[] myListr = {32.649797,32.649693,32.651163};
//25.696042,32.649797
//25.696847,32.649693
//25.697214,32.651163
for(int i=0; i <myListl.length; i++) {
// Add a marker in Sydney and move the camera
LatLng Muscat = new LatLng(myListl[i], myListr[i]);
mMap.addMarker(new MarkerOptions().position(Muscat).title("Grup_num"+i).icon(BitmapDescriptorFactory.fromResource(R.drawable.arrow_location_1))).showInfoWindow();
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(Muscat, 16));
}
mMap.setOnMapClickListener(new GoogleMap.OnMapClickListener() {
#Override
public void onMapClick(LatLng latLng) {
Toast.makeText(MapsActivity.this, latLng.latitude+","+latLng.longitude, Toast.LENGTH_SHORT).show();
mMap.clear();
mMap.addMarker(new MarkerOptions().position(latLng).title("MyLocation")
.icon(BitmapDescriptorFactory.fromResource(R.drawable.arrow_location_1))).showInfoWindow();
}
});
}
}
I'm new to Google maps. Why is is that when I'm trying to zoom in (either with controls or by tapping), after a - relatively high - zoom level the tiles stop loading and all I see is a pixelated view.
Here is my complete activity:
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {
private GoogleMap mMap;
private SupportMapFragment mapFragment;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
#Override
public void onResume() {
System.out.println("Onresume");
mapFragment.onResume();
super.onResume();
}
#Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
LatLng center = new LatLng(47.49801, 19.03991);
mMap.addMarker(new MarkerOptions().position(center).title("Marker"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(center));
}
}
use value required value for zoom laval
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(mLocation, 5f));
A tab within my view pager contains a map view is showing some unexpected behaviour. For some reason whenever I go to a different tab and return to the map view tab, all 4 pins within my map view appear when only 2 of them are supposed to appear. Does anyone know why this has happened? What can be done in order to prevent this from happening?
Stage 1 (flicked the top switch)
Stage 2 (flicked the bottom switch)
Stage 3 (switching to a different tab, then returning back to the map tab)
Java class
public class FragmentCentralPark extends android.support.v4.app.Fragment implements OnMapReadyCallback {
public FragmentCentralPark() {
// Required empty constructor
}
GoogleMap mGoogleMap;
MapView mMapView;
SwitchCompat swt0;
SwitchCompat swt1;
#Override
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_centralpark, container, false);
mMapView = (MapView) v.findViewById(R.id.map_centralpark);
mMapView.onCreate(savedInstanceState);
mMapView.getMapAsync(this); //this is important
swt0 = (SwitchCompat) v.findViewById(R.id.switch0_map_centralpark);
swt1 = (SwitchCompat) v.findViewById(R.id.switch1_map_centralpark);
return v;
}
#Override
public void onMapReady(GoogleMap googleMap) {
mGoogleMap = googleMap;
mGoogleMap.getUiSettings().setZoomControlsEnabled(true);
mGoogleMap.setBuildingsEnabled(true);
mGoogleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
swt0.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
initMap0(isChecked);
}
});
swt1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
initMap1(isChecked);
}
});
initMap0(swt0.isChecked());
initMap1(swt1.isChecked());
// Add markers and move the camera
LatLng centralpark_museum1 = new LatLng(40.785407, -73.957145);
mGoogleMap.addMarker(new MarkerOptions()
.position(centralpark_museum1)
);
LatLng centralpark_museum2 = new LatLng(40.782993, -73.958985);
mGoogleMap.addMarker(new MarkerOptions()
.position(centralpark_museum2)
);
// Updates the location and zoom level of the MapView
CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(new LatLng(40.780437, -73.981063), 16);
mGoogleMap.animateCamera(cameraUpdate);
}
#Override
public void onResume() {
super.onResume();
mMapView.onResume();
}
#Override
public void onPause() {
super.onPause();
mMapView.onPause();
}
#Override
public void onDestroy() {
super.onDestroy();
mMapView.onDestroy();
}
#Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
mMapView.onSaveInstanceState(outState);
}
#Override
public void onLowMemory() {
super.onLowMemory();
mMapView.onLowMemory();
}
private void initMap0(boolean isChecked){
if (isChecked) {
mGoogleMap.setMapStyle(new MapStyleOptions(getResources()
.getString(R.string.style_json)));
} else {
mGoogleMap.setMapStyle(null);
}
}
private void initMap1(boolean isChecked){
if (isChecked) {
mGoogleMap.clear();
// Add markers and move the camera
LatLng centralpark__theatre1 = new LatLng(40.780287, -73.968832);
mGoogleMap.addMarker(new MarkerOptions()
.position(centralpark_theatre1)
);
LatLng centralpark__theatre2 = new LatLng(40.780437, -73.981063);
mGoogleMap.addMarker(new MarkerOptions()
.position(centralpark_theatre2)
);
// Updates the location and zoom level of the MapView
CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(new LatLng(40.780437, -73.981063), 16);
mGoogleMap.animateCamera(cameraUpdate);
} else {
mGoogleMap.clear();
// Add markers and move the camera
LatLng centralpark_museum1 = new LatLng(40.785407, -73.957145);
mGoogleMap.addMarker(new MarkerOptions()
.position(centralpark_museum1)
);
LatLng centralpark_museum2 = new LatLng(40.782993, -73.958985);
mGoogleMap.addMarker(new MarkerOptions()
.position(centralpark_museum2)
);
// Updates the location and zoom level of the MapView
CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(new LatLng(40.780437, -73.981063), 16);
mGoogleMap.animateCamera(cameraUpdate);
}
}
}
I'm trying to to display route between 2 point, but it seems that its tougher than I though, although there are enough posts on the subject.
This is the code I have
public class MainActivity extends FragmentActivity implements OnMapReadyCallback
{
private GoogleMap mMap;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
#Override
public void onMapReady(GoogleMap googleMap)
{
mMap = googleMap;
Context context;
LatLng Current = new LatLng(55.0567842,-1.599155200000041);
LatLng Target = new LatLng(55.0239304,-1.5453314000000091);
LatLngBounds.Builder boundsBuilder = new LatLngBounds.Builder();
boundsBuilder.include(Current);
boundsBuilder.include(Target);
LatLngBounds bounds = boundsBuilder.build();
mMap.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, 3));
PolylineOptions polyOptions = new PolylineOptions();
polyOptions.color(ContextCompat.getColor(context, R.color.colorPrimary));
polyOptions.width(10);
polyOptions.add(Current, Target);
}
Any help with this would be much appreciated.
I cannot get markers on my map from Firebase. I have tried a few examples I found but I can't seem to get it to work. I want all of the locations that I have stored in FireBase to be on one map.
Code:
public class AllJobsMapActivity extends FragmentActivity implements OnMapReadyCallback {
private DatabaseReference geoDatabase = FirebaseDatabase.getInstance().getReference("places");
GoogleMap mapFragment;
List<Marker> markerList = new ArrayList<>();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_all_job_map);
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
#Override
public void onMapReady(final GoogleMap googleMap) {
geoDatabase.addListenerForSingleValueEvent(new ValueEventListener() {
#Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot child : dataSnapshot.child("places").getChildren()) {
String latitude = child.child("lattitude").getValue().toString();
String longitude = child.child("longitude").getValue().toString();
double Latitude = Double.parseDouble(latitude);
double Longitude = Double.parseDouble(longitude);
String name = child.child("name").getValue().toString();
LatLng cod = new LatLng(Latitude, Longitude);
googleMap.addMarker(new MarkerOptions().position(cod).title(name));
}
}
#Override
public void onCancelled(DatabaseError firebaseError) {
}
});
}
}
Firebase Tree: