Map File Embedded Incorrectly (MFEI)

ECn Categories > Browser Embedded Incorrectly (BEI) > Map File Embedded Incorrectly (MFEI)

The app redirects the user to an activity with an Map made in a local file and it does not works because it has no internet connection.

Amount of Issues App List
1 (A24) Forecastie

Examples

Forecastie

Category: Weather
v 1.2
Scenario: To access the weather map without internet connection
This video shows an example of a map file embeded incorectly. At 4th second, the user clicks on the main menu of the app. One of the options displayed is "Weather Map", that will change the current activity. Once the user click on this option at 6th second, a new view that has a option bar at the bottom is displayed, nevertheless due to the connectionless state the map is not loaded and a blank view is displayed to the user.

The following code snippets show the classes and files that are involved in the generation of the previuos issue.

In order to see how this error is generated, we need to review all the flow event. First, as it can be seen at line 616 when the option related to the man is selected a new intent is created at line 617 to open MapActivity.

app/src/main/java/cz/martykan/forecastie/activities/MainActivity.java

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();

        if (id == R.id.action_refresh) {
            if (isNetworkAvailable()) {
                getTodayWeather();
                getLongTermWeather();
            } else {
                Snackbar.make(appView, getString(R.string.msg_connection_not_available), Snackbar.LENGTH_LONG).show();
            }
            return true;
        }
617.    if (id == R.id.action_map) {
618.        Intent intent = new Intent(MainActivity.this, MapActivity.class);
            startActivity(intent);
        }

Second, at the start of the activity “MapActivity” in the “OnCreate” method, between lines 28 and 30 a new WebView is created and at line 30 the url to load is defined, nevertheless as it can be seen is a local url for a map file.

app/src/main/java/cz/martykan/forecastie/activities/MapActivity.java

20. protected void onCreate(Bundle savedInstanceState) {
    ...
        final WebView webView = (WebView) findViewById(R.id.webView);
        webView.getSettings().setJavaScriptEnabled(true);
30.     webView.loadUrl("file:///android_asset/map.html?lat=" + prefs.getFloat("latitude", 0) + 
            "&lon=" + prefs.getFloat("longitude", 0) + "&appid=" + apiKey);

Now we have to see the content of the map file. At line 21 it can be seen the html tag that displays the map

app/src/main/assets/map.html

21. <div id='map'>
    </div>

Finally, there is the JS snippet that binds the result from leaflet library to the div from the previous snippet

app/src/main/assets/map.html

40. var map = L.map('map', {
        zoomControl: true,
        attributionControl: false
    }).setView([getUrlParameter('lon'), getUrlParameter('lat')], 7);