本文介绍了自定义地图标记点与毕加索未加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用Custom标记实现android Mapview。我正在使用picasso将图像加载到标记视图中。但这些地图并没有显示出我需要的标记。



这是我的代码

  i = getIntent(); 
if(i.getBooleanExtra(maps,true)){
mactionBar.setSubtitle(i.getStringExtra(nama));
mMyMarkersArray.add(新的MyMarker(i.getStringExtra(nama),i.getStringExtra(deskripsi),i.getStringExtra(foto),i.getStringExtra(marker),Double.parseDouble (i.getStringExtra(lat)),Double.parseDouble(i.getStringExtra(lng))));
plotMarkers(mMyMarkersArray);
}

这里是加载图片标记的代码。我正在执行 if(i.getBooleanExtra(maps,true)),因为有两个活动导致这个mapsview。如果以前的活动提供了真实值,那么它将只带来一个标记数据。但是如果该值为假,它将带来所有标记数据。 mapsview向我展示了我需要的所有标记,如果它是从之前带来错误值的活动中获得的。但是,如果mapsview从带来真实价值的活动中获得,那么mapsview不会显示出标记。

  public void plotMarkers(ArrayList< MyMarker>标记){
if(markers.size()> 0){
for(MyMarker myMarker:markers)
{
markerOption = new MarkerOptions()。position新的LatLng(myMarker.getmLatitude(),myMarker.getmLongitude()));
location_marker = mMap.addMarker(markerOption);
Target target = new PicassoMarker(location_marker);
targets.add(target);
Picasso.with(MapsActivity.this).load(myMarker.getmIcon())。resize(84,125).into(target);
mMarkersHashMap.put(location_marker,myMarker);

i = getIntent();
if(i.getBooleanExtra(maps,true)){
buttonNavigasi.setVisibility(View.VISIBLE);

location_marker.setTitle(i.getStringExtra(nama));
dest = new LatLng(myMarker.getmLatitude(),myMarker.getmLongitude());
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(dest,16));
}
else {
mMap.setInfoWindowAdapter(new MarkerInfoWindowAdapter());






这里是关于如何调用MapsActivity的代码

  buttonNavigasi =(AppCompatButton)findViewById(R.id.button2); 
buttonNavigasi.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v){
Intent i = new Intent(DetailActivity.this,MapsActivity.class );
i.putExtra(nama,daftarNama);
i.putExtra(deskripsi,daftarDeskripsi);
i.putExtra(foto,daftarFoto);
i.putExtra(marker,daftarMarker);
i.putExtra(lng,daftarLng);
i.putExtra(lat,daftarLat);
i.putExtra maps,true);
startActivity(i);
}
});

以下是plotMarkers的方法



<$ p $ (MyMarker myMarker:标记)
($ marker)$ {
if(markers.size()> 0){
public void plotMarkers(ArrayList< MyMarker>标记) {
markerOption = new MarkerOptions()。position(new LatLng(myMarker.getmLatitude(),myMarker.getmLongitude()));
location_marker = mMap.addMarker(markerOption);
Target target = new PicassoMarker(location_marker);
targets.add(target);
Picasso.with(MapsActivity.this).load(myMarker.getmIcon())。resize(84,125).into(target);
mMarkersHashMap.put(location_marker,myMarker);

i = getIntent();
if(i.getBooleanExtra(maps,true)){
buttonNavigasi.setVisibility(View.VISIBLE);

location_marker.setTitle(i.getStringExtra(nama));
dest = new LatLng(myMarker.getmLatitude(),myMarker.getmLongitude());
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(dest,16));
}
else {
mMap.setInfoWindowAdapter(new MarkerInfoWindowAdapter());
}
}
}
}



PicassoMarker class

  public class PicassoMarker实现Target {
Marker mMarker;

PicassoMarker(标记标记){
mMarker = marker;


@Override
public int hashCode(){
return mMarker.hashCode();

$ b @Override
public boolean equals(Object o){
if(o instanceof PicassoMarker){
Marker marker =((PicassoMarker)o ).mMarker;
return mMarker.equals(marker);
} else {
return false;
}
}

@Override
public void onBitmapLoaded(位图位图,Picasso.LoadedFrom from){
mMarker.setIcon(BitmapDescriptorFactory.fromBitmap(bitmap ));

$ b @Override
public void onBitmapFailed(Drawable errorDrawable){
}
$ b $ @Override
public void onPrepareLoad( Drawable placeHolderDrawable){
}
}

这里有什么问题?



谢谢。

解决方案

我使用Handler以延迟显示标记。所以我改变我的代码像这样

  i = getIntent(); 
if(i.getBooleanExtra(maps,true)){
ActionBar mactionBar = getSupportActionBar();
mactionBar.setSubtitle(i.getStringExtra(nama));
buttonNavigasi.setVisibility(View.VISIBLE);
mMyMarkersArray.add(新的MyMarker(i.getStringExtra(nama),i.getStringExtra(deskripsi),i.getStringExtra(foto),i.getStringExtra(marker),Double.parseDouble (i.getStringExtra(lat)),Double.parseDouble(i.getStringExtra(lng))));

Handler UI_HANDLER = new Handler();
UI_HANDLER.postDelayed(UI_UPDATE_RUNNABLE,500);
}

而且

  Runnable UI_UPDATE_RUNNABLE = new Runnable(){
@Override
public void run(){
plotMarkers(mMyMarkersArray);
}
};


I'm implementing android Mapview with Custom marker. I'm using picasso to load image into marker view. But the maps not shows me the marker that i needed.

Here's my code

i = getIntent();
    if(i.getBooleanExtra("maps", true)) {
        mactionBar.setSubtitle(i.getStringExtra("nama"));
        mMyMarkersArray.add(new MyMarker(i.getStringExtra("nama"), i.getStringExtra("deskripsi"), i.getStringExtra("foto"), i.getStringExtra("marker"), Double.parseDouble(i.getStringExtra("lat")), Double.parseDouble(i.getStringExtra("lng"))));
        plotMarkers(mMyMarkersArray);
    }

Here the code to load image marker. I'm implementing if(i.getBooleanExtra("maps", true)) because there are two activities that lead to this mapsview. If the previous activity put a true value, then it will bring just one marker data. But if the value is false, it will bring all markers data. The mapsview shows me all the markers that i needed if it got from the previous activity that bring false value. But the mapsview not shows me a marker if it got from the activity that bring the true value.

public void plotMarkers(ArrayList<MyMarker> markers) {
    if(markers.size() > 0) {
        for (MyMarker myMarker : markers)
        {
            markerOption = new MarkerOptions().position(new LatLng(myMarker.getmLatitude(), myMarker.getmLongitude()));
            location_marker = mMap.addMarker(markerOption);
            Target target = new PicassoMarker(location_marker);
            targets.add(target);
            Picasso.with(MapsActivity.this).load(myMarker.getmIcon()).resize(84, 125).into(target);
            mMarkersHashMap.put(location_marker, myMarker);

            i = getIntent();
            if(i.getBooleanExtra("maps", true)) {
                buttonNavigasi.setVisibility(View.VISIBLE);

                location_marker.setTitle(i.getStringExtra("nama"));
                dest = new LatLng(myMarker.getmLatitude(), myMarker.getmLongitude());
                mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(dest, 16));
            }
            else {
                mMap.setInfoWindowAdapter(new MarkerInfoWindowAdapter());
            }
        }
    }
}

Here's the the code on how i call the MapsActivity

buttonNavigasi = (AppCompatButton) findViewById(R.id.button2);
    buttonNavigasi.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent i = new Intent(DetailActivity.this,MapsActivity.class);
            i.putExtra("nama", daftarNama);
            i.putExtra("deskripsi", daftarDeskripsi);
            i.putExtra("foto", daftarFoto);
            i.putExtra("marker", daftarMarker);
            i.putExtra("lng", daftarLng);
            i.putExtra("lat", daftarLat);
            i.putExtra("maps", true);
            startActivity(i);
        }
    });

Here's the method of plotMarkers

public void plotMarkers(ArrayList<MyMarker> markers) {
    if(markers.size() > 0) {
        for (MyMarker myMarker : markers)
        {
            markerOption = new MarkerOptions().position(new LatLng(myMarker.getmLatitude(), myMarker.getmLongitude()));
            location_marker = mMap.addMarker(markerOption);
            Target target = new PicassoMarker(location_marker);
            targets.add(target);
            Picasso.with(MapsActivity.this).load(myMarker.getmIcon()).resize(84, 125).into(target);
            mMarkersHashMap.put(location_marker, myMarker);

            i = getIntent();
            if(i.getBooleanExtra("maps", true)) {
                buttonNavigasi.setVisibility(View.VISIBLE);

                location_marker.setTitle(i.getStringExtra("nama"));
                dest = new LatLng(myMarker.getmLatitude(), myMarker.getmLongitude());
                mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(dest, 16));
            }
            else {
                mMap.setInfoWindowAdapter(new MarkerInfoWindowAdapter());
            }
        }
    }
}

PicassoMarker class

public class PicassoMarker implements Target {
Marker mMarker;

    PicassoMarker(Marker marker) {
        mMarker = marker;
    }

    @Override
    public int hashCode() {
        return mMarker.hashCode();
    }

    @Override
    public boolean equals(Object o) {
        if(o instanceof PicassoMarker) {
            Marker marker = ((PicassoMarker) o).mMarker;
            return mMarker.equals(marker);
        } else {
            return false;
        }
    }

    @Override
    public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
       mMarker.setIcon(BitmapDescriptorFactory.fromBitmap(bitmap));
    }

    @Override
    public void onBitmapFailed(Drawable errorDrawable) {
    }

    @Override
    public void onPrepareLoad(Drawable placeHolderDrawable) {
    }
}

What's wrong here?

Thanks.

解决方案

I use Handler to show the markers with some delay. So i change my code like this

i = getIntent();
if(i.getBooleanExtra("maps", true)) {
    ActionBar mactionBar = getSupportActionBar();
    mactionBar.setSubtitle(i.getStringExtra("nama"));
    buttonNavigasi.setVisibility(View.VISIBLE);
    mMyMarkersArray.add(new MyMarker(i.getStringExtra("nama"), i.getStringExtra("deskripsi"), i.getStringExtra("foto"), i.getStringExtra("marker"), Double.parseDouble(i.getStringExtra("lat")), Double.parseDouble(i.getStringExtra("lng"))));

    Handler UI_HANDLER = new Handler();
    UI_HANDLER.postDelayed(UI_UPDATE_RUNNABLE, 500);
}

And this

Runnable UI_UPDATE_RUNNABLE = new Runnable() {
    @Override
    public void run() {
        plotMarkers(mMyMarkersArray);
    }
};

这篇关于自定义地图标记点与毕加索未加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 10:11