Search in sources :

Example 21 with LatLng

use of fr.free.nrw.commons.location.LatLng in project apps-android-commons by commons-app.

the class NearbyListFragment method onViewCreated.

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    // Check that this is the first time view is created,
    // to avoid double list when screen orientation changed
    Bundle bundle = this.getArguments();
    Gson gson = new GsonBuilder().registerTypeAdapter(Uri.class, new UriDeserializer()).create();
    if (bundle != null) {
        String gsonPlaceList = bundle.getString("PlaceList");
        String gsonLatLng = bundle.getString("CurLatLng");
        Type listType = new TypeToken<List<Place>>() {
        }.getType();
        placeList = gson.fromJson(gsonPlaceList, listType);
        Type curLatLngType = new TypeToken<LatLng>() {
        }.getType();
        LatLng curLatLng = gson.fromJson(gsonLatLng, curLatLngType);
        placeList = NearbyController.loadAttractionsFromLocationToPlaces(curLatLng, placeList);
    }
    if (savedInstanceState == null) {
        adapter.clear();
        Timber.d("Saved instance state is null, populating ListView");
    }
    adapter.clear();
    adapter.addAll(placeList);
    adapter.notifyDataSetChanged();
}
Also used : Type(java.lang.reflect.Type) GsonBuilder(com.google.gson.GsonBuilder) Bundle(android.os.Bundle) Gson(com.google.gson.Gson) List(java.util.List) LatLng(fr.free.nrw.commons.location.LatLng) Uri(android.net.Uri) UriDeserializer(fr.free.nrw.commons.utils.UriDeserializer)

Example 22 with LatLng

use of fr.free.nrw.commons.location.LatLng in project apps-android-commons by commons-app.

the class MediaDataExtractor method getCoordinates.

/**
     * Extracts the coordinates from the template and returns them as pretty formatted string.
     * Loops over the children of the coordinate template:
     *      {{Location|47.50111007666667|19.055700301944444}}
     * and extracts the latitude and longitude as a pretty string.
     *
     * @param parentNode The node of the coordinates template.
     * @return Pretty formatted coordinates.
     * @throws IOException Parsing failed.
     */
private String getCoordinates(Node parentNode) throws IOException {
    NodeList childNodes = parentNode.getChildNodes();
    double latitudeText = Double.parseDouble(childNodes.item(1).getTextContent());
    double longitudeText = Double.parseDouble(childNodes.item(2).getTextContent());
    LatLng coordinates = new LatLng(latitudeText, longitudeText, 0);
    return coordinates.getPrettyCoordinateString();
}
Also used : NodeList(org.w3c.dom.NodeList) LatLng(fr.free.nrw.commons.location.LatLng)

Aggregations

LatLng (fr.free.nrw.commons.location.LatLng)22 Test (org.junit.Test)16 Bundle (android.os.Bundle)2 NearbyBaseMarker (fr.free.nrw.commons.nearby.NearbyBaseMarker)2 BufferedReader (java.io.BufferedReader)2 InputStreamReader (java.io.InputStreamReader)2 URL (java.net.URL)2 ArrayList (java.util.ArrayList)2 Uri (android.net.Uri)1 StrictMode (android.os.StrictMode)1 OnItemClick (butterknife.OnItemClick)1 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 Place (fr.free.nrw.commons.nearby.Place)1 UriDeserializer (fr.free.nrw.commons.utils.UriDeserializer)1 IOException (java.io.IOException)1 Type (java.lang.reflect.Type)1 URLConnection (java.net.URLConnection)1 List (java.util.List)1 Matcher (java.util.regex.Matcher)1