android-mapview
Google Maps Android API V2 check if GoogleMaps are installed on device
Alright after more poking and prodding I realized I just need to ask PackageManager if google maps are installed. IMO this should really be included in the Google Maps Android API V2 developers guide…there are going to be lots of devs that miss this case and have frustrated users. Here’s how to check if Google … Read more
Google Maps Android API v2 very slow when adding lots of Markers
Alright, after trying a couple more things I figured out how to determine if a given point is in the visible region, and it’s pretty simple: //Note: this.mMap is an instance of GoogleMap LatLngBounds bounds = this.mMap.getProjection().getVisibleRegion().latLngBounds; LatLng markerPoint = new LatLng(item.getLatitude(), item.getLongitude()); if(bounds.contains(markerPoint)) { this.mMap.addMarker(new MarkerOptions(…)); } *Note that getting the projection of the … Read more
How do you draw text with a border on a MapView in Android?
The easiest way to do this is with a Stroke… something like this: @Override public void draw(Canvas canvas, MapView mapView, boolean shadow) { Paint strokePaint = new Paint(); strokePaint.setARGB(255, 0, 0, 0); strokePaint.setTextAlign(Paint.Align.CENTER); strokePaint.setTextSize(16); strokePaint.setTypeface(Typeface.DEFAULT_BOLD); strokePaint.setStyle(Paint.Style.STROKE); strokePaint.setStrokeWidth(2); Paint textPaint = new Paint(); textPaint.setARGB(255, 255, 255, 255); textPaint.setTextAlign(Paint.Align.CENTER); textPaint.setTextSize(16); textPaint.setTypeface(Typeface.DEFAULT_BOLD); canvas.drawText(“Some Text”, 100, 100, strokePaint); canvas.drawText(“Some … Read more
Get altitude by longitude and latitude in Android
My approach is to use USGS Elevation Query Web Service: private double getAltitude(Double longitude, Double latitude) { double result = Double.NaN; HttpClient httpClient = new DefaultHttpClient(); HttpContext localContext = new BasicHttpContext(); String url = “http://gisdata.usgs.gov/” + “xmlwebservices2/elevation_service.asmx/” + “getElevation?X_Value=” + String.valueOf(longitude) + “&Y_Value=” + String.valueOf(latitude) + “&Elevation_Units=METERS&Source_Layer=-1&Elevation_Only=true”; HttpGet httpGet = new HttpGet(url); try { HttpResponse … Read more
Relocate Google logo in MapView
Google Maps SDK v2 for Android adds this functionality. Use GoogleMap.setPadding() to add padding to the “active” area (including the Google logo and copyright notices) while still filling the full container. https://developers.google.com/maps/documentation/android/map#map_padding
Android Maps Point Clustering
Last night i got into PointClustering on Android MapView. Saw that there was nothing out for the community so i would like to share. Groups the geopoints if the projection of them in the mapView is too close. Also renders only the visible poins. UPDATE Code reworked from scrach. Now available at GitHub Code Reworked … Read more