diff --git a/app/src/main/java/org/ntlab/amaryllis/client/fragment/MapsFragment.java b/app/src/main/java/org/ntlab/amaryllis/client/fragment/MapsFragment.java index 680755a..0e4c0d5 100644 --- a/app/src/main/java/org/ntlab/amaryllis/client/fragment/MapsFragment.java +++ b/app/src/main/java/org/ntlab/amaryllis/client/fragment/MapsFragment.java @@ -32,10 +32,12 @@ import com.google.android.gms.maps.CameraUpdateFactory; import com.google.android.gms.maps.GoogleMap; import com.google.android.gms.maps.OnMapReadyCallback; +import com.google.android.gms.maps.Projection; import com.google.android.gms.maps.SupportMapFragment; import com.google.android.gms.maps.model.CameraPosition; import com.google.android.gms.maps.model.LatLng; import com.google.android.gms.maps.model.MarkerOptions; +import com.google.android.gms.maps.model.VisibleRegion; import org.ntlab.amaryllis.client.Amaryllis; import org.ntlab.amaryllis.client.MainActivity; @@ -109,10 +111,11 @@ // String longitude = amaryllis.getLongitude(); // double latitude1 = Double.parseDouble(latitude); // double longitude1 = Double.parseDouble(longitude); - LatLng sydney = new LatLng(35, 135); -// MapsFragment.this= - googleMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney")); - googleMap.moveCamera(CameraUpdateFactory.newLatLng(sydney)); + + + + MapsFragment.this.googlemap = googleMap; + } }; @@ -175,20 +178,35 @@ @Override public void onLocationChanged(Location location) { - Log.d("DEBUG", "lat : " + location.getLatitude()); - Log.d("DEBUG", "lon : " + location.getLongitude()); - Call> call = voicememosService.getVoicememos(latmax,latmin,longmax,longmin); - call.enqueue(new Callback>() { - @Override - public void onResponse(Call> call, Response> response) { + if(googlemap != null) { + Log.d("DEBUG", "lat : " + location.getLatitude()); + Log.d("DEBUG", "lon : " + location.getLongitude()); + LatLng sydney = new LatLng(location.getLatitude(), location.getLongitude()); + MapsFragment.this.googlemap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney")); + MapsFragment.this.googlemap.moveCamera(CameraUpdateFactory.newLatLng(sydney)); + Projection p = googlemap.getProjection(); + VisibleRegion vr = p.getVisibleRegion(); + latmax = vr.latLngBounds.northeast.latitude; + latmin = vr.latLngBounds.southwest.latitude; + longmax = vr.latLngBounds.northeast.longitude; + longmin = vr.latLngBounds.southwest.longitude; +// System.out.println(latmax + "!!!!!!!!!!!!!"); +// System.out.println(latmin + "!!!!!!!!!!!!!"); +// System.out.println(longmax + "!!!!!!!!!!!!!"); +// System.out.println(longmin + "!!!!!!!!!!!!!"); + Call> call = voicememosService.getVoicememos(latmax, latmin, longmax, longmin); + call.enqueue(new Callback>() { + @Override + public void onResponse(Call> call, Response> response) { - } + } - @Override - public void onFailure(Call> call, Throwable t) { + @Override + public void onFailure(Call> call, Throwable t) { - } - }); + } + }); + } }