gpt4 book ai didi

android - Google map v2 的自定义信息窗口

转载 作者:行者123 更新时间:2023-11-30 02:40:02 26 4
gpt4 key购买 nike

我正在尝试自定义信息窗口并在加载 map 时显示它。自定义信息窗口出现了,但是,随着默认的信息窗口背景(白色),我还没有为它出现的标记设置图标?为什么我得到的是这个默认值?

这是我尝试的屏幕截图:

enter image description here

我不想要白色窗口和标记图标?我正在尝试实现类似以下屏幕截图的效果:How to create a custom-shaped bitmap marker with Android map API v2

这是我正在尝试的:

public class Mapstwo extends Fragment implements GoogleMap.OnMyLocationChangeListener
{
private GoogleMap googleMap;
private GPSTracker gps;
private double curlat;
private double curlong;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
if (rootView != null)
{
ViewGroup parent = (ViewGroup) rootView.getParent();
if (parent != null)
parent.removeView(rootView);
}
try
{
rootView = inflater.inflate(R.layout.activity_locate_me_maps, container, false);
}
catch (InflateException e)
{

}

if (initMap())
{
gps = new GPSTracker(fa);
curlat = gps.getLatitude();
curlong = gps.getLongitude();
gps.stopUsingGPS();

myLocation(curlat, curlong, username, imageURL, ZOOMVALUE);
}
else
{
Toast.makeText(getActivity().getApplicationContext(),"Sorry! Map not available!", Toast.LENGTH_SHORT).show();
}


return rootView;
}


private boolean initMap()
{
if (googleMap == null)
{
SupportMapFragment mapFrag = ((SupportMapFragment) getFragmentManager().findFragmentById(R.id.map));
googleMap = mapFrag.getMap();
googleMap.setTrafficEnabled(true);
//googleMap.setMyLocationEnabled(true);
googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
googleMap.setOnMyLocationChangeListener(this);
}

return (googleMap != null);
}


//MY LOCATION
private void myLocation(double lat, double lng, String name, String url, float zoom)
{

final String uname = name;
curlat = getLat;
curlong = getLong;
LatLng position = new LatLng(curlat, curlong);

markermylocation = googleMap.addMarker(new MarkerOptions().position(position).title(uname).snippet("Testing is everthing OK?"));
markers.put(markermylocation.getId(), imageURL);
googleMap.setInfoWindowAdapter(new CustomInfoWindowAdapter());
markermylocation.showInfoWindow();

}


@SuppressLint("InflateParams")
private class CustomInfoWindowAdapter implements InfoWindowAdapter
{
@Override
public View getInfoWindow(Marker arg0)
{
return null;
}

@Override
public View getInfoContents(Marker marker)
{
View v = getActivity().getLayoutInflater().inflate(R.layout.activity_map, null);

Log.e("View","Sucessful");

return v;
}
}

}

最佳答案

试试这段代码,你需要改变默认的布局框架,你需要在getInfoWindow()中设置你的inflate View

// Use default InfoWindow frame
@Override
public View getInfoWindow(Marker arg0) {
View v = getActivity().getLayoutInflater().inflate(R.layout.activity_map, null);
Log.e("View","Sucessful");
return v;
}

// Defines the contents of the InfoWindow
@Override
public View getInfoContents(Marker arg0) {
return null;
}

您有默认内容布局中的膨胀 View ,因此更改以膨胀 View 。

关于android - Google map v2 的自定义信息窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25925653/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com