0

I use osmdroid and Mapnik! My problem is when I use geo fix command, I can see the longitude and latitude new values on my screen but not the position, I mean my map don't move to my new position. Can someone help. I always get this error: 10-29 10:31:43.649: I/dalvikvm(309): Could not find method android.animation.ValueAnimator.ofFloat, referenced from method org.osmdroid.views.MapController.<init> Here is my code:

    package com.formation.mine;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.osmdroid.DefaultResourceProxyImpl;
import org.osmdroid.ResourceProxy;
import org.osmdroid.api.IMapView;
import org.osmdroid.tileprovider.tilesource.TileSourceFactory;
import org.osmdroid.util.GeoPoint;
import org.osmdroid.util.ResourceProxyImpl;
import org.osmdroid.views.MapView;
import org.osmdroid.views.overlay.ItemizedOverlay;
import org.osmdroid.views.overlay.OverlayItem;

import android.app.Activity;
import android.content.Context;
import android.graphics.Point;
import android.graphics.drawable.Drawable;
import android.location.Address;
import android.location.Geocoder;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.TextView;
import android.widget.Toast;


public class MainActivity extends Activity implements LocationListener {


    LocationManager locationManager; 
    Geocoder geocoder;                                                   //convertit les adresses en latitude et longitude
    TextView locationText;
    ResourceProxy mResourceProxy;
    MapView m_mapview;

    //Constantes
    double LATITUDE = -12.276610;
    double LONGITUDE = 49.292531;     //Grand Hotel


    // Called when the activity is first created
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        GeoPoint point = new GeoPoint( microdegrees (LATITUDE) , microdegrees(LONGITUDE));
        mResourceProxy = new ResourceProxyImpl(getApplicationContext());
        MonOverlay object = new MonOverlay(getResources().getDrawable(R.drawable.marker), mResourceProxy);
        locationManager = (LocationManager)this.getSystemService(LOCATION_SERVICE);
        geocoder = new Geocoder(this); 

        locationText = (TextView)this.findViewById(R.id.lblLocationInfo);
        m_mapview = (MapView) findViewById(R.id.mapview);

        m_mapview.setBuiltInZoomControls(true);
        m_mapview.setMultiTouchControls(true);
        m_mapview.setUseDataConnection(true);
        m_mapview.setBackgroundColor(BIND_AUTO_CREATE);                                //encore à choisir une couleur
        object.addPoint(point);
        m_mapview.getOverlays().add(object);
        m_mapview.getController().setZoom(15);
        m_mapview.getController().setCenter(point);
        m_mapview.setTileSource(TileSourceFactory.MAPNIK);

    }

            //Pour avoir les valeurs des latitudes et longitudes en degré
            private int microdegrees(double value){
                return (int)(value*1000000);
            }

            //Classe et Méthodes d'Overlays
            public class MonOverlay extends ItemizedOverlay<OverlayItem>{

                    List<GeoPoint> points = new ArrayList<GeoPoint>();
                    public MonOverlay(Drawable pDefaultMarker,
                            ResourceProxy pResourceProxy) {
                        super(pDefaultMarker, pResourceProxy);
                        // TODO Auto-generated constructor stub
                    }
                    @Override
                    public boolean onSnapToItem(int i, int arg1, Point arg2,
                            IMapView arg3) {
                        // TODO Auto-generated method stub
                        return false;
                    }
                    @Override
                    protected OverlayItem createItem(int i) {
                        GeoPoint point = points.get(i);
                        return new OverlayItem("Description","Titre",point);                               
                    }
                    @Override
                    public int size() {
                        return points.size();
                    }
                    public void addPoint(GeoPoint point){
                        this.points.add(point);
                        populate();
                    }               
            }

            //LES METHODES DU LOCATION-MANAGER
            @Override
            protected void onResume() {
                super.onResume();
                locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 10, this); //<7>
            }

            @Override
            protected void onPause() {
                super.onPause();
                locationManager.removeUpdates(this); 
            }

            @Override
            public void onLocationChanged(Location location) { 
                String text = String.format("Latitude:\t %f\nLongitude:\t %f\nAltitude:\t %f\nBearing:\t %f", location.getLatitude(), 
                        location.getLongitude(), location.getAltitude(), location.getBearing());

                Context context = getApplicationContext();
                  int duration = Toast.LENGTH_LONG;
                  Toast toast = Toast.makeText(context,text, duration);
                  toast.show();


                try {
                    List<Address> addresses = geocoder.getFromLocation(location.getLatitude(), location.getLongitude(), 10);
                    for (Address address : addresses) {
                        this.locationText.append("\n" + address.getAddressLine(0)); }

                    int latitude = (int)(location.getLatitude() * 1000000);
                    int longitude = (int)(location.getLongitude() * 1000000);

                    GeoPoint point = new GeoPoint(latitude,longitude);
                    mResourceProxy = new DefaultResourceProxyImpl(getApplicationContext());
//                  m_mapview.getController().animateTo(point); 

                    MonOverlay object = new MonOverlay(getResources().getDrawable(R.drawable.marker), mResourceProxy);
                    object.addPoint(point);
                    m_mapview.getOverlays().add(object);
                    m_mapview.getController().setZoom(15);
                    m_mapview.getController().setCenter(point);


                } catch (IOException e) {
                    Log.e("LocateMe", "Could not get Geocoder data", e);
                }


            }
            @Override
            public void onProviderDisabled(String arg0) {
                // TODO Auto-generated method stub  
            }
            @Override
            public void onProviderEnabled(String arg0) {
                // TODO Auto-generated method stub
            }
            @Override
            public void onStatusChanged(String arg0, int arg1, Bundle arg2) {
                // TODO Auto-generated method stub
            }


            //CREATION DES METHODES MENUS
            @Override
            public boolean onCreateOptionsMenu(Menu menu) {
                // Inflate the menu; appel au menu.menu
                 MenuInflater inflater = getMenuInflater();
                    inflater.inflate(R.menu.menu,menu);                  //menu.ma_position
                    return true;
            }
            //Pour le choix des menus
            @Override
            public boolean onOptionsItemSelected(MenuItem item) {
                // Handle item selection
                switch (item.getItemId()) {
                    case R.id.item1:
                    Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); 
                    if (location != null) {
                        this.onLocationChanged(location);
                      }else{
                          Context context = getApplicationContext();
                          int duration = Toast.LENGTH_SHORT;
                          Toast toast = Toast.makeText(context, "Vous êtes toujours sur la même position", duration);
                          toast.show();

                      }
                        return true;
//                  case R.id.help:
//                      showHelp();
//                      return true;
                    default:
                        return super.onOptionsItemSelected(item);
                }
            }
}           

As I said, I get this errors when I press the menu "Ma position" (itme1) Here is some errors:

    10-30 14:54:55.181: I/dalvikvm(306): Could not find method android.animation.ValueAnimator.ofFloat, referenced from method org.osmdroid.views.MapController.<init>
10-30 14:54:55.191: W/dalvikvm(306): VFY: unable to resolve static method 14: Landroid/animation/ValueAnimator;.ofFloat ([F)Landroid/animation/ValueAnimator;
10-30 14:54:55.191: D/dalvikvm(306): VFY: replacing opcode 0x71 at 0x001a
10-30 14:54:55.201: D/dalvikvm(306): VFY: dead code 0x001d-005d in Lorg/osmdroid/views/MapController;.<init> (Lorg/osmdroid/views/MapView;)V
10-30 14:54:55.221: I/dalvikvm(306): Could not find method android.animation.Animator.end, referenced from method org.osmdroid.views.MapController.stopAnimation
10-30 14:54:55.221: W/dalvikvm(306): VFY: unable to resolve virtual method 6: Landroid/animation/Animator;.end ()V
10-30 14:54:55.231: D/dalvikvm(306): VFY: replacing opcode 0x6e at 0x002e
10-30 14:54:55.251: I/dalvikvm(306): Could not find method android.animation.ValueAnimator.start, referenced from method org.osmdroid.views.MapController.zoomInFixing
10-30 14:54:55.251: W/dalvikvm(306): VFY: unable to resolve virtual method 16: Landroid/animation/ValueAnimator;.start ()V
10-30 14:54:55.261: D/dalvikvm(306): VFY: replacing opcode 0x6e at 0x0039
10-30 14:54:55.281: I/dalvikvm(306): Could not find method android.animation.ValueAnimator.start, referenced from method org.osmdroid.views.MapController.zoomOutFixing
10-30 14:54:55.281: W/dalvikvm(306): VFY: unable to resolve virtual method 16: Landroid/animation/ValueAnimator;.start ()V
10-30 14:54:55.281: D/dalvikvm(306): VFY: replacing opcode 0x6e at 0x0039
10-30 14:54:55.331: I/org.osmdroid.views.MapView(306): Using tile source: org.osmdroid.tileprovider.tilesource.XYTileSource@43e515d8
10-30 14:54:55.411: I/org.osmdroid.tileprovider.modules.MapTileFileStorageProviderBase(306): sdcard state: mounted
10-30 14:54:55.431: I/org.osmdroid.tileprovider.modules.MapTileFileStorageProviderBase(306): sdcard state: mounted
10-30 14:54:56.701: D/dalvikvm(306): GC_FOR_MALLOC freed 2917 objects / 198880 bytes in 189ms
10-30 14:54:57.322: D/dalvikvm(306): GC_FOR_MALLOC freed 2200 objects / 114080 bytes in 117ms
10-30 14:54:57.971: D/dalvikvm(306): GC_FOR_MALLOC freed 2010 objects / 119912 bytes in 113ms
10-30 14:54:58.752: D/dalvikvm(306): GC_FOR_MALLOC freed 1626 objects / 122632 bytes in 205ms
10-30 14:54:59.642: D/dalvikvm(306): GC_FOR_MALLOC freed 2119 objects / 118352 bytes in 309ms
10-30 14:55:00.672: D/dalvikvm(306): GC_FOR_MALLOC freed 2680 objects / 147576 bytes in 137ms
10-30 14:55:01.532: D/dalvikvm(306): GC_FOR_MALLOC freed 2817 objects / 223456 bytes in 166ms
10-30 14:55:02.291: I/org.osmdroid.tileprovider.MapTileProviderBase(306): rescale tile cache from 0 to 15
10-30 14:55:02.341: D/dalvikvm(306): DexOpt: couldn't find field Landroid/graphics/BitmapFactory$Options;.inBitmap
10-30 14:55:02.351: W/dalvikvm(306): VFY: unable to resolve instance field 33
10-30 14:55:02.351: D/dalvikvm(306): VFY: replacing opcode 0x5b at 0x000b
10-30 14:55:02.351: D/dalvikvm(306): VFY: dead code 0x000d-0010 in Lorg/osmdroid/tileprovider/BitmapPool;.applyReusableOptions (Landroid/graphics/BitmapFactory$Options;)V
10-30 14:55:02.391: I/org.osmdroid.tileprovider.MapTileProviderBase(306): Finished rescale in 94ms
10-30 14:55:02.641: D/dalvikvm(306): GC_EXTERNAL_ALLOC freed 3924 objects / 224384 bytes in 206ms
10-30 14:55:03.171: D/dalvikvm(306): GC_EXTERNAL_ALLOC freed 756 objects / 167616 bytes in 171ms
10-30 14:55:03.941: D/dalvikvm(306): GC_EXTERNAL_ALLOC freed 595 objects / 63304 bytes in 320ms
10-30 14:55:09.831: D/dalvikvm(306): GC_FOR_MALLOC freed 24577 objects / 1568904 bytes in 255ms
10-30 14:55:09.882: W/KeyCharacterMap(306): No keyboard for id 0
10-30 14:55:09.892: W/KeyCharacterMap(306): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
10-30 14:56:17.341: E/LocateMe(306): Could not get Geocoder data
10-30 14:56:17.341: E/LocateMe(306): java.io.IOException: Service not Available
10-30 14:56:17.341: E/LocateMe(306):    at android.location.Geocoder.getFromLocation(Geocoder.java:117)
10-30 14:56:17.341: E/LocateMe(306):    at com.formation.mine.MainActivity.onLocationChanged(MainActivity.java:138)
10-30 14:56:17.341: E/LocateMe(306):    at android.location.LocationManager$ListenerTransport._handleMessage(LocationManager.java:191)
10-30 14:56:17.341: E/LocateMe(306):    at android.location.LocationManager$ListenerTransport.access$000(LocationManager.java:124)
10-30 14:56:17.341: E/LocateMe(306):    at android.location.LocationManager$ListenerTransport$1.handleMessage(LocationManager.java:140)
10-30 14:56:17.341: E/LocateMe(306):    at android.os.Handler.dispatchMessage(Handler.java:99)
10-30 14:56:17.341: E/LocateMe(306):    at android.os.Looper.loop(Looper.java:123)
10-30 14:56:17.341: E/LocateMe(306):    at android.app.ActivityThread.main(ActivityThread.java:4627)
10-30 14:56:17.341: E/LocateMe(306):    at java.lang.reflect.Method.invokeNative(Native Method)
10-30 14:56:17.341: E/LocateMe(306):    at java.lang.reflect.Method.invoke(Method.java:521)
10-30 14:56:17.341: E/LocateMe(306):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
10-30 14:56:17.341: E/LocateMe(306):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
10-30 14:56:17.341: E/LocateMe(306):    at dalvik.system.NativeStart.main(Native Method)
Taryn
  • 242,637
  • 56
  • 362
  • 405
Mina
  • 11
  • 6
  • The problem appears when I press the "Ma position" buton on the menu, so when calling the onLocationChanged(). – Mina Oct 30 '14 at 04:39
  • Reference link : http://android-coding.blogspot.in/2012/06/example-of-implementing-openstreetmap.html – VVB Oct 30 '14 at 07:05
  • Eclipse says to me that the type MyMocationOverlay is deprecated!!! and I get also a lot of error! I can't run my program – Mina Oct 30 '14 at 09:46
  • It might be because you are using old library – VVB Oct 30 '14 at 10:27
  • I use osmdroid-android-4.2.jar and slf4j-android-1.5.8.jar! what's wrong with my code, I would like to see my position! – Mina Oct 30 '14 at 11:33
  • Post some errors/log – VVB Oct 30 '14 at 11:38
  • Effectively, MyLocationOverlay is deprecated, and replaced by MyLocationNewOverlay. By the way, you have another issue about accessing to Geocoder service. – MKer Oct 30 '14 at 13:42
  • thanks for your suggestion! What issue? I don't really understand! using Geocoder instead of MyLocationNewOverlay? – Mina Nov 01 '14 at 06:06
  • I would like to ask if osmdroid is supporting by the Google API 8? thanks – Mina Nov 01 '14 at 06:30

1 Answers1

0

i guess your problem is this

java.io.IOException: Service not Available

watch these two link as it seems to be a common bug

Service not Available - Geocoder Android

Service not available while calling geoCoder.getFromLocation()

these are two Common ways to solve your problem: 1. reboot your Device. maybe you disabled that service from setting of your phone 2. add

uses-permission android:name="android.permission.INTERNET"

to your manifest

Community
  • 1
  • 1
Omid Heshmatinia
  • 5,089
  • 2
  • 35
  • 50
  • thanks for your answer but I would like to do all things offline! someone tells me to put all the information that I need in a text file but how can I call the Textfile from my program and use it? – Mina Nov 09 '14 at 09:04
  • Dear Mina, NEVER even think about collecting all geocoding information of your city and read it from a Text file !!!!! geocoding is not just put some names and latitude longitude in a text file!!!!!! you should parse it and find the most near location to your location then parse its address! i do not say its impossible but pay attention to Two Important things! 1. Where do u wanna collect your information from?! you should do it by yourself! 2. after collection you should write your parser! – Omid Heshmatinia Nov 09 '14 at 10:31
  • so KML and GPX are used for what? I use osmbonuspack actually! – Mina Nov 09 '14 at 10:48
  • i never find any place to give me THE KML of geocoding of any city ! if u find that, show it to me too! and also, even if u have the kml, its just names and coordinates. you should parse it again by yourself :D i mean you should do the calculates by yourself – Omid Heshmatinia Nov 09 '14 at 16:37