mapsForge do not show the map

1,475 views
Skip to first unread message

Yordan Estrada

unread,
Jun 12, 2015, 8:58:51 AM6/12/15
to mapsfo...@googlegroups.com
Hi every one, i'm trying to follow the "A very basic Android app example" with mapsforge 0.5.1, I am using my own map created on osmosis-latest using mapsforge-map-writer-0.5.1.jar named camaguey.map (the map is attached), when I compile my apk it works fine, but it just show an empty interface, it don't show the maps, this is my code, can anyone helpme to find where is the problem??


MainActivity code


package org.example.newmap;

import java.io.File;

import org.mapsforge.core.model.LatLong;
import org.mapsforge.map.android.graphics.AndroidGraphicFactory;
import org.mapsforge.map.android.util.AndroidUtil;
import org.mapsforge.map.android.view.MapView;
import org.mapsforge.map.layer.cache.TileCache;
import org.mapsforge.map.layer.renderer.TileRendererLayer;
import org.mapsforge.map.reader.MapDataStore;
import org.mapsforge.map.reader.MapFile;
import org.mapsforge.map.rendertheme.InternalRenderTheme;

import android.app.Activity;
import android.os.Bundle;
import android.os.Environment;
import android.widget.Toast;

public class MainActivity extends Activity {

    // name of the map file in the external storage
    private static final String MAPFILE = "camaguey.map";

    private MapView mapView;   
    private TileCache tileCache;
    private TileRendererLayer tileRendererLayer;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        AndroidGraphicFactory.createInstance(this.getApplication());

        this.mapView = new MapView(this);
        setContentView(this.mapView);

        this.mapView.setClickable(true);
        this.mapView.getMapScaleBar().setVisible(true);
        this.mapView.setBuiltInZoomControls(true);
        this.mapView.getMapZoomControls().setZoomLevelMin((byte) 10);
        this.mapView.getMapZoomControls().setZoomLevelMax((byte) 20);

        // create a tile cache of suitable size
        this.tileCache = AndroidUtil.createTileCache(this, "mapcache",
                mapView.getModel().displayModel.getTileSize(), 1f,
                this.mapView.getModel().frameBufferModel.getOverdrawFactor());
    }

    @Override
    protected void onStart() {
        super.onStart();

        this.mapView.getModel().mapViewPosition.setCenter(new LatLong(22.0933, -76.9565));
        this.mapView.getModel().mapViewPosition.setZoomLevel((byte) 20);

        File a = getMapFile();
        Toast.makeText(this, a.getAbsolutePath().toString() + " existe: " + a.exists(), Toast.LENGTH_SHORT).show(); 
       
        // tile renderer layer using internal render theme
        MapDataStore mapDataStore = new MapFile(a);
        this.tileRendererLayer = new TileRendererLayer(tileCache, mapDataStore,
                this.mapView.getModel().mapViewPosition, false, true, AndroidGraphicFactory.INSTANCE);
        tileRendererLayer.setXmlRenderTheme(InternalRenderTheme.OSMARENDER);

        // only once a layer is associated with a mapView the rendering starts
        this.mapView.getLayerManager().getLayers().add(tileRendererLayer);

    }

    @Override
    protected void onStop() {
        super.onStop();
        this.mapView.getLayerManager().getLayers().remove(this.tileRendererLayer);
        this.tileRendererLayer.onDestroy();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        this.tileCache.destroy();
        this.mapView.getModel().mapViewPosition.destroy();
        this.mapView.destroy();
        AndroidGraphicFactory.clearResourceMemoryCache();
    }

    private File getMapFile() {       
        File file = new File(Environment.getExternalStorageDirectory(), MAPFILE);            
        return file;
    }

}


AndroidManifest.xml


<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="org.example.newmap"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="18" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.WAKE_LOCK"/>
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="org.example.newmap.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

            
camaguey.map

Andy Greaves

unread,
Jun 12, 2015, 9:03:30 AM6/12/15
to Emux
I can confirm that there is nothing wrong with your map. I viewed it using the SwingMapViewer. 

Inline images 1

Andy

--
You received this message because you are subscribed to the Google Groups "mapsforge-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mapsforge-de...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mapsforge-dev/ee8e2326-e896-4437-8242-9ff25156a683%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Emux

unread,
Jun 12, 2015, 9:09:36 AM6/12/15
to mapsfo...@googlegroups.com
Your map indeed has content.

But your position is at map borders (20.6431,-78.6786,22.0933,-76.9565) where there are no data to see.

--
Emux
Cruiser - Atlas

Yordan Estrada

unread,
Jun 15, 2015, 12:41:25 PM6/15/15
to mapsfo...@googlegroups.com
wow!!!, so I'm really lost, cause I used the position using:
http://www.openstreetmap.org/export#map=9/21.0819/-78.2556,

please, can you give me a position to use in
this.mapView.getModel().mapViewPosition.setCenter(new LatLong( , ));
to see my map???

--
You received this message because you are subscribed to a topic in the Google Groups "mapsforge-dev" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mapsforge-dev/yogcE2Dk-ow/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mapsforge-de...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mapsforge-dev/557ADA0B.2050507%40gmail.com.

Emux

unread,
Jun 15, 2015, 12:48:22 PM6/15/15
to mapsfo...@googlegroups.com
It's rather simple, in your code you have set as location one of the map corners.

Try somewhere in the middle, e.g. Camagüey coordinates (21.383889, -77.9075) and a smaller zoom level 12.

Yordan Estrada

unread,
Jun 15, 2015, 1:28:19 PM6/15/15
to mapsfo...@googlegroups.com
Well, I don't know what's wrong cause I do everything you said and still do not work, I can't see nothing...  As you can see, I am new using mapsForge, can you help me to find what is wrong, I dont know why I can't see nothing, I'm sending the code after the changes, can you give me another example to see if mine is wrong or something....
(the image of what shows the project is attached)
        this.mapView.getModel().mapViewPosition.setCenter(new LatLong(21.383889, -77.9075));

        this.mapView.getModel().mapViewPosition.setZoomLevel((byte) 20);

        File a = getMapFile();
       // Toast.makeText(this, a.getAbsolutePath().toString() + " existe: " + a.exists(), Toast.LENGTH_SHORT).show(); 
       
        // tile renderer layer using internal render theme
        MapDataStore mapDataStore = new MapFile(a);
        this.tileRendererLayer = new TileRendererLayer(tileCache, mapDataStore,
                this.mapView.getModel().mapViewPosition, false, true, AndroidGraphicFactory.INSTANCE);
        tileRendererLayer.setXmlRenderTheme(InternalRenderTheme.OSMARENDER);

        // only once a layer is associated with a mapView the rendering starts
        this.mapView.getLayerManager().getLayers().add(tileRendererLayer);

    }

    @Override
    protected void onStop() {
        super.onStop();
        this.mapView.getLayerManager().getLayers().remove(this.tileRendererLayer);
        this.tileRendererLayer.onDestroy();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        this.tileCache.destroy();
        this.mapView.getModel().mapViewPosition.destroy();
        this.mapView.destroy();
        AndroidGraphicFactory.clearResourceMemoryCache();
    }

    private File getMapFile() {       
        File file = new File(Environment.getExternalStorageDirectory(), MAPFILE);            
        return file;
    }

}

--
You received this message because you are subscribed to a topic in the Google Groups "mapsforge-dev" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mapsforge-dev/yogcE2Dk-ow/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mapsforge-de...@googlegroups.com.
326.gif
ejemplo.png

Emux

unread,
Jun 15, 2015, 1:42:07 PM6/15/15
to mapsfo...@googlegroups.com
Try setting android:hardwareAccelerated="false" in your manifest.
You can follow Samples manifest for reference.

Yordan Estrada

unread,
Jun 15, 2015, 3:04:37 PM6/15/15
to mapsfo...@googlegroups.com
nop, hardwareAccelerated="false" do not solve the problem... 

--
You received this message because you are subscribed to a topic in the Google Groups "mapsforge-dev" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mapsforge-dev/yogcE2Dk-ow/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mapsforge-de...@googlegroups.com.
326.gif

Emux

unread,
Jun 15, 2015, 3:45:46 PM6/15/15
to mapsfo...@googlegroups.com
Can you post your code (java, layout, manifest) and stack trace from the logs, it could help us understand what happens.

Yordan Estrada

unread,
Jun 15, 2015, 4:10:58 PM6/15/15
to mapsfo...@googlegroups.com
All right here is all my code, besides the project and the map are attached in the mail:
the NewMap1 file is just a .rar file, but as google don't allow me to send it as .rar (I suppose is because it detects it as an android project), you just have to change the 1 for .rar and there is my project.

thanks a lot for your time...

MainActivity.java
activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />

</RelativeLayout>

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="org.example.newmap"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="9"
        android:targetSdkVersion="22" />

    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.WAKE_LOCK"/>
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" android:hardwareAccelerated="true">

        <activity
            android:name="org.example.newmap.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>



--
You received this message because you are subscribed to a topic in the Google Groups "mapsforge-dev" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mapsforge-dev/yogcE2Dk-ow/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mapsforge-de...@googlegroups.com.
NewMap1
camaguey.map

Emux

unread,
Jun 15, 2015, 4:39:30 PM6/15/15
to mapsfo...@googlegroups.com
The solution is simple if you take a look at your stack trace (exceptions for missing classes).

You need to configure better your libs (you don't have AndroidSVG jar).

Also don't mix Android and Java jars.

You can find the needed components per platform at our wiki:
https://github.com/mapsforge/mapsforge/blob/master/docs/Getting-Started-Developers.md#components

Yordan Estrada

unread,
Jun 15, 2015, 4:44:27 PM6/15/15
to mapsfo...@googlegroups.com
Hum, sorry, as I already said, I am new in this topic, and in android topics generaly, I am a c++ programmer trying to learn android jejeje

can you please send me the fixed project in a .rar file as i do?? so I can see it and it will be easier to learn for me.

thanks again
greetins yordan

--
You received this message because you are subscribed to a topic in the Google Groups "mapsforge-dev" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mapsforge-dev/yogcE2Dk-ow/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mapsforge-de...@googlegroups.com.

Emux

unread,
Jun 15, 2015, 4:57:45 PM6/15/15
to mapsfo...@googlegroups.com
On 15/06/2015 11:44 μμ, Yordan Estrada wrote:
Hum, sorry, as I already said, I am new in this topic, and in android topics generaly, I am a c++ programmer trying to learn android jejeje

It's ok, step by step.


can you please send me the fixed project in a .rar file as i do?? so I can see it and it will be easier to learn for me.

I attach the libs folder with the Mapsforge needed jars for Android (the rest project remains the same).

androidsvg-1.2.2-beta-1.jar
kxml2-2.3.0.jar
mapsforge-core-0.5.1.jar
mapsforge-map-0.5.1.jar
mapsforge-map-android-0.5.1.jar
mapsforge-map-reader-0.5.1.jar

Yordan Estrada

unread,
Jun 16, 2015, 9:24:28 AM6/16/15
to mapsfo...@googlegroups.com
it works ... !!!! thanks a lot Emux, right now you'r my hero jejeje,
Just two things:
- can you tell me where I can learn how to make a marker???
- mapsForge support gps location?? where I can learn about it??

I can't find too much information on the web about mapsforge...
thanks again
yordan

On Mon, Jun 15, 2015 at 10:57 PM, Emux <deve...@gmail.com> wrote:
On 15/06/2015 11:44 μμ, Yordan Estrada wrote:
Hum, sorry, as I already said, I am new in this topic, and in android topics generaly, I am a c++ programmer trying to learn android jejeje

It's ok, step by step.

can you please send me the fixed project in a .rar file as i do?? so I can see it and it will be easier to learn for me.

I attach the libs folder with the Mapsforge needed jars for Android (the rest project remains the same).

(replace _ with . in zip file name)


--
Emux
Cruiser - Atlas

--
You received this message because you are subscribed to a topic in the Google Groups "mapsforge-dev" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mapsforge-dev/yogcE2Dk-ow/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mapsforge-de...@googlegroups.com.
330.gif

Emux

unread,
Jun 16, 2015, 9:30:12 AM6/16/15
to mapsfo...@googlegroups.com
On 16/06/2015 04:24 μμ, Yordan Estrada wrote:
- can you tell me where I can learn how to make a marker???
- mapsForge support gps location?? where I can learn about it??

You best guide is the Samples app.

It has many examples of Mapsforge API (like those you ask).

Yordan Estrada

unread,
Jun 16, 2015, 11:33:50 AM6/16/15
to mapsfo...@googlegroups.com
Hello EMUX, you have been very helpful, I was looking about markers, but the examples I have found are for mapsForge 0.3, I'm dealing with this:

MyMarker marker = new MyMarker (this, new LatLong (21.383889,-77.9075),AndroidGraphicFactory.convertToBitmap(getResources().getDrawable(R.drawable.ic_launcher)),0,0);
.. This.mapView.getLayerManager () getLayers () add (marker);

Create a "MyMarker" class that extends Marker, and I try to use it, but it does not work, I mean, the map does not show the mark ...
Why it might be going ???


On the other hand, I do not know how to access examples of which I have spoken, the only thing I see is there the rotation of the map ...

--
You received this message because you are subscribed to a topic in the Google Groups "mapsforge-dev" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mapsforge-dev/yogcE2Dk-ow/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mapsforge-de...@googlegroups.com.

Emux

unread,
Jun 16, 2015, 12:06:55 PM6/16/15
to mapsfo...@googlegroups.com
You can get Samples apk from downloads and check the examples in a device / emulator.

Study carefully its activities code, each one shows a specific aspect of Mapsforge features.
e.g. the overlays are described in OverlayMapViewer


This is probably beyond the scope of Mapsforge mailing list.

I understand you're using Eclipse for development IDE?

We provide instructions for building Mapsforge components (i.e. Samples) in wiki via jars, Maven, Gradle etc.

For Eclipse it could be as simple as creating a new empty Android project and throw in it the Samples resources and code along with the libs.

I strongly recommend to familiarize yourself with Android development first and dive in Mapsforge world step by step.

Yordan Estrada

unread,
Jun 23, 2015, 1:27:06 PM6/23/15
to mapsfo...@googlegroups.com
Hi Emux, I am trying to put a text on each marker, so I can show the
name of the place in the map..., do you have any code example to do
that???
I'm using mapsforge 0.5.1.

thanks for your time.
yordan

On 6/16/15, Emux <deve...@gmail.com> wrote:
> You can get Samples apk from downloads
> <https://github.com/mapsforge/mapsforge/blob/master/docs/Downloads.md>
> and check the examples in a device / emulator.
>
> Study carefully its activities code, each shows a specific aspect of
> Mapsforge features.
> e.g. the overlays are described in OverlayMapViewer
> <https://github.com/mapsforge/mapsforge/blob/master/Applications/Android/Samples/src/main/java/org/mapsforge/applications/android/samples/OverlayMapViewer.java>
>
>
> This is probably beyond the scope of Mapsforge mailing list.
>
> I understand you're using Eclipse for development IDE?
>
> We provide instructions for building Mapsforge components (i.e. Samples)
> in wiki
> <https://github.com/mapsforge/mapsforge/blob/master/docs/Getting-Started-Developers.md>
>
> via jars, Maven, Gradle etc.
>
> For Eclipse it could be as simple as creating a new empty Android
> project and throw in it the Samples resources and code along with the libs.
>
> I strongly recommend to familiarize yourself with Android development
> and take the entry in Mapsforge world step by step.
>
> --
> Emux
> Cruiser <http://wiki.openstreetmap.org/wiki/Cruiser> - Atlas
> <http://wiki.openstreetmap.org/wiki/Atlas_%28navigation_application%29>
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "mapsforge-dev" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/mapsforge-dev/yogcE2Dk-ow/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> mapsforge-de...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/mapsforge-dev/5580499C.8000604%40gmail.com.

Emux

unread,
Jun 23, 2015, 1:36:15 PM6/23/15
to mapsfo...@googlegroups.com
You can extend Marker.draw in order to use canvas.drawText after canvas.drawBitmap.

I think we have a similar case in Samples LongPressAction example.

Yordan Estrada

unread,
Jun 23, 2015, 2:05:18 PM6/23/15
to mapsfo...@googlegroups.com
Hi Emux
Which is the Utils library used in the example??

private static final Paint BLACK =
Utils.createPaint(AndroidGraphicFactory.INSTANCE.createColor(Color.BLACK),
0,Style.FILL);

because createPaint method do not work, and eclipse cannot resolve it.
> Cruiser <http://wiki.openstreetmap.org/wiki/Cruiser> - Atlas
> <http://wiki.openstreetmap.org/wiki/Atlas_%28navigation_application%29>
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "mapsforge-dev" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/mapsforge-dev/yogcE2Dk-ow/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> mapsforge-de...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/mapsforge-dev/5589990D.6030305%40gmail.com.

Emux

unread,
Jun 23, 2015, 2:07:29 PM6/23/15
to mapsfo...@googlegroups.com
On 23/06/2015 09:05 μμ, Yordan Estrada wrote:
Which is the Utils library used in the example??

That's org.mapsforge.applications.android.samples.Utils class inside Samples project.

Yordan Estrada

unread,
Jun 23, 2015, 2:28:42 PM6/23/15
to mapsfo...@googlegroups.com
That's fine Emux, but what I really want is to show the text in a bubble...
I want to show a bubble like the one used in comics and books...
do you have any example like that??

On 6/23/15, Emux <deve...@gmail.com> wrote:
> Cruiser <http://wiki.openstreetmap.org/wiki/Cruiser> - Atlas
> <http://wiki.openstreetmap.org/wiki/Atlas_%28navigation_application%29>
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "mapsforge-dev" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/mapsforge-dev/yogcE2Dk-ow/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> mapsforge-de...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/mapsforge-dev/5589A05E.9010704%40gmail.com.

Emux

unread,
Jun 23, 2015, 2:30:28 PM6/23/15
to mapsfo...@googlegroups.com
You need to study Samples better :)

Check BubbleOverlay example.

Yordan Estrada

unread,
Jun 25, 2015, 1:12:04 PM6/25/15
to mapsfo...@googlegroups.com
Hello EMUX, you were right, I found what I was needing in the examples, now can you tell me what example I use to learn how to use the GPS location mapsforge ??

thanks a lot
yordan

--
You received this message because you are subscribed to a topic in the Google Groups "mapsforge-dev" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mapsforge-dev/yogcE2Dk-ow/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mapsforge-de...@googlegroups.com.

Emux

unread,
Jun 25, 2015, 1:13:59 PM6/25/15
to mapsfo...@googlegroups.com
That would be the LocationOverlayMapViewer.

Yordan Estrada

unread,
Jun 25, 2015, 1:55:13 PM6/25/15
to mapsfo...@googlegroups.com
Hello Emux indeed this very simple code in the example, but when I try to include my GPS position on the map, not shown, on the contrary, the application stops working, I assume is due to the delay of GPS to search the position, you had this problem, I let my code here

package cupet.eccmg.cupetdroid;

import java.io.File;
import java.util.ArrayList;

import org.mapsforge.core.graphics.Bitmap;
import org.mapsforge.core.model.LatLong;
import org.mapsforge.map.android.graphics.AndroidGraphicFactory;
import org.mapsforge.map.android.layer.MyLocationOverlay;

import org.mapsforge.map.android.util.AndroidUtil;
import org.mapsforge.map.android.view.MapView;
import org.mapsforge.map.layer.cache.TileCache;
import org.mapsforge.map.layer.overlay.Marker;

import org.mapsforge.map.layer.renderer.TileRendererLayer;
import org.mapsforge.map.reader.MapDataStore;
import org.mapsforge.map.reader.MapFile;
import org.mapsforge.map.rendertheme.InternalRenderTheme;

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Environment;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;


public class MapActivity extends Activity {


    // name of the map file in the external storage
    private static final String MAPFILE = "cupetdroid/camaguey.map";


    private MapView mapView;   
    private TileCache tileCache;
    private TileRendererLayer tileRendererLayer;
    private DataBase bd = new DataBase();

    private double centerLat = 21.383889;
    private double centerLon = -77.9075;

    private MyLocationOverlay myLocationOverlay;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        AndroidGraphicFactory.createInstance(this.getApplication());


        this.mapView = new MapView(this);
        setContentView(this.mapView);

        this.mapView.setClickable(true);
        this.mapView.getMapScaleBar().setVisible(true);
        this.mapView.setBuiltInZoomControls(true);   

        this.mapView.getMapZoomControls().setZoomLevelMin((byte) 10);
        this.mapView.getMapZoomControls().setZoomLevelMax((byte) 20);       
        this.mapView.getModel().mapViewPosition.setZoomLevel((byte) 17);
        this.mapView.getModel().mapViewPosition.setCenter(new LatLong(centerLat, centerLon));


        // create a tile cache of suitable size
        this.tileCache = AndroidUtil.createTileCache(this, "mapcache",
                mapView.getModel().displayModel.getTileSize(), 1f,
                this.mapView.getModel().frameBufferModel.getOverdrawFactor());
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater=getMenuInflater();
        inflater.inflate(R.menu.main, menu);
        return super.onCreateOptionsMenu(menu);

    }

    @Override
    protected void onStart() {
        super.onStart();                     

        ArrayList<Localizacion> items = bd.mostrar(this);
        File a = getMapFile();


        MapDataStore mapDataStore = new MapFile(a);
        this.tileRendererLayer = new TileRendererLayer(tileCache, mapDataStore,
                this.mapView.getModel().mapViewPosition, false, true, AndroidGraphicFactory.INSTANCE);
        tileRendererLayer.setXmlRenderTheme(InternalRenderTheme.OSMARENDER);

        this.mapView.getLayerManager().getLayers().add(tileRendererLayer);

        Bundle extras = getIntent().getExtras();
        if (extras != null) {
            centerLat = getIntent().getExtras().getDouble("latitud");
            centerLon = getIntent().getExtras().getDouble("longitud");
            this.mapView.getModel().mapViewPosition.setCenter(new LatLong(centerLat, centerLon));
        }   

        for(Localizacion item : items) {
            this.createMarker(new LatLong(item.getLatitud(), item.getLongitud()),item);
            this.createBubble(new LatLong(item.getLatitud(), item.getLongitud()),item.getNombre());
        }       
    }

    @Override
    public void onBackPressed() {
        super.onBackPressed();
        this.finish();
    }
   
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (item.getItemId() == R.id.GPS)
            this.activateGPS();        
        return (super.onOptionsItemSelected(item));
    }

   

    public void activateGPS(){
        Bitmap bitmap = AndroidGraphicFactory.convertToBitmap(getResources().getDrawable(R.drawable.mail));
        this.myLocationOverlay = new MyLocationOverlay(this,this.mapView.getModel().mapViewPosition, bitmap);
        this.myLocationOverlay.setSnapToLocationEnabled(true);
        this.myLocationOverlay.enableMyLocation(true);
        mapView.getLayerManager().getLayers().add(this.myLocationOverlay);
    }


    private void createMarker(LatLong pos,Localizacion item){
        MyMarker marker = new MyMarker(this,item,pos,AndroidGraphicFactory.convertToBitmap(getResources().getDrawable(R.drawable.venta_marker)),0,0);
        this.mapView.getLayerManager().getLayers().add(marker);                
    }

    private void createBubble(LatLong pos,String name){
        TextView bubbleView = new TextView(this);
        Utils.setBackground(bubbleView, getResources().getDrawable(R.drawable.balloon_overlay_unfocused));
        bubbleView.setGravity(Gravity.CENTER);
        bubbleView.setMaxEms(20);
        bubbleView.setTextSize(15);
        bubbleView.setTextColor(Color.BLACK);
        bubbleView.setText(name);
        Bitmap bubble = Utils.viewToBitmap(this, bubbleView);
        bubble.incrementRefCount();
        this.mapView.getLayerManager().getLayers().add(new Marker(pos, bubble, 0, -bubble.getHeight()-12));
    }

    @Override
    protected void onStop() {
        super.onStop();
        this.mapView.getLayerManager().getLayers().remove(this.tileRendererLayer);
        this.tileRendererLayer.onDestroy();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        this.tileCache.destroy();
        this.mapView.getModel().mapViewPosition.destroy();
        this.mapView.destroy();
        AndroidGraphicFactory.clearResourceMemoryCache();
    }

    private File getMapFile() {       
        File file = new File(Environment.getExternalStorageDirectory(), MAPFILE);            
        return file;
    }

}

--
You received this message because you are subscribed to a topic in the Google Groups "mapsforge-dev" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mapsforge-dev/yogcE2Dk-ow/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mapsforge-de...@googlegroups.com.

Emux

unread,
Jun 25, 2015, 2:07:51 PM6/25/15
to mapsfo...@googlegroups.com
Does the Samples location example works for you?

It would help to provide a stack trace from logcat in order to see the problem.

BTW I recommend creating the MyLocationOverlay once in onCreate and just enable it whenever you want.
Remember to disable it when you don't need it, i.e. in onPause

Yordan Estrada

unread,
Jul 1, 2015, 1:10:21 PM7/1/15
to mapsfo...@googlegroups.com
Hi Emux, let me ask you something, this is not really about mapsforge, why my apk can work in some phones but there are some phones that don't allow it to run, I mean, my apk works easily in many phones, but in some, it starts and show the splash, but when the apk call another activity it just stop. Can you help me??

thanks a lot
yordan

--
You received this message because you are subscribed to a topic in the Google Groups "mapsforge-dev" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mapsforge-dev/yogcE2Dk-ow/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mapsforge-de...@googlegroups.com.

Emux

unread,
Jul 1, 2015, 1:22:21 PM7/1/15
to mapsfo...@googlegroups.com
Unfortunately without seeing a log, it's difficult to guess what's the problem.
(if you have it on Google Play check its developer console)

You cannot debug your app in such a device?
Or learn what Android version has and test it on a corresponding emulator?

My first assumption is that you maybe use some new Android API code
and the app crashes on devices with older Android that don't support that code.

e.g. the proper call for view.setLayerType (added in API level 11) is:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
    view.setLayerType(View.LAYER_TYPE_SOFTWARE, null);

Yordan Estrada

unread,
Jul 1, 2015, 1:36:53 PM7/1/15
to mapsfo...@googlegroups.com
Here is the log in the device,it have a 4.3 android, is a Like phone, model: N9002.
My apk' name is cupetdroid

--
You received this message because you are subscribed to a topic in the Google Groups "mapsforge-dev" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mapsforge-dev/yogcE2Dk-ow/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mapsforge-de...@googlegroups.com.
log.png

Emux

unread,
Jul 1, 2015, 1:50:59 PM7/1/15
to mapsfo...@googlegroups.com
The log shows an Out Of Memory exception.

So you need to check what you're doing in the app and that situation happens.

Yordan Estrada

unread,
Jul 8, 2015, 2:33:35 PM7/8/15
to mapsfo...@googlegroups.com
Hi Emux, i am trying to use daimajia/AndroidImageSlider in my project, but It library do not work, may be because I don't know how to fix it, but the demo example do not recognize some clases in the library, so have you use this library and in this case, can you give me any example that works, because I don't know what else to do to fix it.

https://github.com/daimajia/AndroidImageSlider

thanks a lot
yordan

--
You received this message because you are subscribed to a topic in the Google Groups "mapsforge-dev" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mapsforge-dev/yogcE2Dk-ow/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mapsforge-de...@googlegroups.com.

Emux

unread,
Jul 8, 2015, 2:58:43 PM7/8/15
to mapsfo...@googlegroups.com
Do you have an issue with Mapsforge regarding that library, or specifically with that library itself?

Any library specific questions should be asked at its respective mailing / issues list.

Yordan Estrada

unread,
Jul 9, 2015, 11:43:52 AM7/9/15
to mapsfo...@googlegroups.com
Hi Emux, my mistake, I have not explained well, the problem is that i am
trying to use both libraries in the same project, and mapsforge does not
work, in the case that only use mapsforge, it works perfectly, so I am
thinking is a problem with the refered libraries or something like that.
Attached is the log.


thanks

On Wed, Jul 8, 2015 at 8:58 PM, Emux <deve...@gmail.com> wrote:
Sorry I didn't understand.

Do you have an issue with Mapsforge regarding that library, or specifically with that library itself?

I haven't used it and any library specific questions should be asked on its related mailing / issues list.

--
Emux
Cruiser - Atlas

--
You received this message because you are subscribed to a topic in the Google Groups "mapsforge-dev" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mapsforge-dev/yogcE2Dk-ow/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mapsforge-de...@googlegroups.com.
error.png

Emux

unread,
Jul 9, 2015, 11:53:20 AM7/9/15
to mapsfo...@googlegroups.com
Take a close look at your log.

There is a "file does not exist" exception, regarding the map file path.

Yordan Estrada

unread,
Jul 10, 2015, 8:42:48 AM7/10/15
to mapsfo...@googlegroups.com
Hi emux, you were right, thanks, now I have a doubt, and I dont know where to ask for help....
I want to assign an id to a generated bitmap, I already have some reserved ids in an ids.xml file inside values, and the generated bitmap,  can you help me or can you redirect me to the place I can ask for help??

--
You received this message because you are subscribed to a topic in the Google Groups "mapsforge-dev" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mapsforge-dev/yogcE2Dk-ow/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mapsforge-de...@googlegroups.com.

Emux

unread,
Jul 10, 2015, 8:48:18 AM7/10/15
to mapsfo...@googlegroups.com
On 10/07/2015 03:42 μμ, Yordan Estrada wrote:
can you redirect me to the place I can ask for help??

Reply all
Reply to author
Forward
0 new messages