Detect when Android v2 maps has loaded

OnMapLoadedCallback doesn’t fire until after the tiles on map are loaded. Only fires once so you’ll have to call it nine times to take nine snapshots. When you have a reference to the map set the call back. mMap.setOnMapLoadedCallback(this); When the onMapLoaded event fires take the snapshot. @Override public void onMapLoaded() { if (mMap != … Read more

Android – Save image from URL onto SD card

Try this code.It works… try { URL url = new URL(“Enter the URL to be downloaded”); HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection(); urlConnection.setRequestMethod(“GET”); urlConnection.setDoOutput(true); urlConnection.connect(); File SDCardRoot = Environment.getExternalStorageDirectory().getAbsoluteFile(); String filename=”downloadedFile.png”; Log.i(“Local filename:”,””+filename); File file = new File(SDCardRoot,filename); if(file.createNewFile()) { file.createNewFile(); } FileOutputStream fileOutput = new FileOutputStream(file); InputStream inputStream = urlConnection.getInputStream(); int totalSize = urlConnection.getContentLength(); int … Read more

How To add custom View in map’s Annotation’s Callout’s

I had same problem and ended up doing following thing: When I receive mapView delegate callback -(void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view (it’s time when I want to show my custom CalloutView) I use view received as parameter *(MKAnnotationView )view (which is a pin view) and simply add my custom view to that pin view using [view … Read more

How to GeoCode a simple address using Data Science Toolbox

Like this: library(httr) library(rjson) data <- paste0(“[“,paste(paste0(“\””,dff$address,”\””),collapse=”,”),”]”) url <- “http://www.datasciencetoolkit.org/street2coordinates” response <- POST(url,body=data) json <- fromJSON(content(response,type=”text”)) geocode <- do.call(rbind,sapply(json, function(x) c(long=x$longitude,lat=x$latitude))) geocode # long lat # San Francisco, California, United States -117.88536 35.18713 # Mobile, Alabama, United States -88.10318 30.70114 # La Jolla, California, United States -117.87645 33.85751 # Duarte, California, United States -118.29866 33.78659 … Read more

Get the distance between two geo points

Location loc1 = new Location(“”); loc1.setLatitude(lat1); loc1.setLongitude(lon1); Location loc2 = new Location(“”); loc2.setLatitude(lat2); loc2.setLongitude(lon2); float distanceInMeters = loc1.distanceTo(loc2); Reference: http://developer.android.com/reference/android/location/Location.html#distanceTo(android.location.Location)

Android – SupportMapFragment with GoogleMaps API 2.0 giving IllegalArgumentException

You can fix this, if you delete all nested fragments in onDestroyView(). Don’t know if it is a proper solution. public void onDestroyView() { super.onDestroyView(); Fragment fragment = (getFragmentManager().findFragmentById(R.id.map)); FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction(); ft.remove(fragment); ft.commit(); } And inflating them as usual in onCreateView() public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { return inflater.inflate(R.layout.map, container, … Read more

How can I quickly estimate the distance between two (latitude, longitude) points?

The answers to Haversine Formula in Python (Bearing and Distance between two GPS points) provide Python implementations that answer your question. Using the implementation below I performed 100,000 iterations in less than 1 second on an older laptop. I think for your purposes this should be sufficient. However, you should profile anything before you optimize … Read more

midpoint between two latitude and longitude

You need to convert to radians. Change it to the following: public static void midPoint(double lat1,double lon1,double lat2,double lon2){ double dLon = Math.toRadians(lon2 – lon1); //convert to radians lat1 = Math.toRadians(lat1); lat2 = Math.toRadians(lat2); lon1 = Math.toRadians(lon1); double Bx = Math.cos(lat2) * Math.cos(dLon); double By = Math.cos(lat2) * Math.sin(dLon); double lat3 = Math.atan2(Math.sin(lat1) + Math.sin(lat2), … Read more