Skip to content

Commit

Permalink
#1: Adding leaflet map.
Browse files Browse the repository at this point in the history
  • Loading branch information
YouQam committed Sep 27, 2019
1 parent 941435b commit 72d1e1a
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 9 deletions.
4 changes: 4 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.greenwave">
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<application
android:allowBackup="true"
Expand Down
35 changes: 34 additions & 1 deletion app/src/main/java/com/example/greenwave/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,46 @@

import androidx.appcompat.app.AppCompatActivity;

import android.content.Context;
import android.os.Bundle;
import android.preference.PreferenceManager;

public class MainActivity extends AppCompatActivity {
import org.osmdroid.api.IMapController;
import org.osmdroid.config.Configuration;
import org.osmdroid.tileprovider.tilesource.TileSourceFactory;
import org.osmdroid.util.GeoPoint;
import org.osmdroid.views.MapView;
import org.osmdroid.views.overlay.Marker;

public class MainActivity extends AppCompatActivity {
MapView mapView = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);



//load/initialize the osmdroid configuration, this can be done
Context ctx = getApplicationContext();
Configuration.getInstance().load(ctx, PreferenceManager.getDefaultSharedPreferences(ctx));

//inflate and create the map
setContentView(R.layout.activity_main);

mapView = (MapView) findViewById(R.id.map);
mapView.setTileSource(TileSourceFactory.MAPNIK);


Marker startMarker = new Marker(mapView);
startMarker.setIcon(mapView.getContext().getResources().getDrawable(R.drawable.you_are_here));
GeoPoint startPoint = new GeoPoint(51.9521884,7.6382983);
startMarker.setPosition(startPoint);
mapView.getOverlays().add(startMarker);
startMarker.setTitle("You are here!");

IMapController mapController = mapView.getController();
mapController.setCenter(startPoint);
mapController.setZoom(15.5);
}
}
Binary file added app/src/main/res/drawable/you_are_here.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 6 additions & 8 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@
android:layout_height="match_parent"
tools:context=".MainActivity">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<org.osmdroid.views.MapView
android:id="@+id/map"
android:layout_weight="0.5"
android:layout_width="match_parent"
android:layout_height="match_parent"
tilesource="Mapnik"/>

</androidx.constraintlayout.widget.ConstraintLayout>

0 comments on commit 72d1e1a

Please sign in to comment.