当前位置:首页 > 代码 > 正文

android百度地图提示框代码(android调用百度地图api)

admin 发布:2022-12-19 14:00 146


今天给各位分享android百度地图提示框代码的知识,其中也会对android调用百度地图api进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

安卓开发之百度地图中地址显示提示框效果要怎么加?

那是因为还没有加载完,加载成功之后就可以定位了, 我在用腾讯的地图,卫星定位精确到周边十米,在家里小区的超市大门都可以看见,高清的图像,360度的全景,任意的旋转、移动、变换,丰富的景点和较为全面的街景覆盖,给人眼前一亮的感觉。还可以可以看到彼此的实时位置,新增实时位置共享服务,一键查看好友的实时位置与距离

希望可以帮到你,满意望采纳

android开发百度地图怎么实现自定义弹出窗口

基本原理就是用ItemizedOverlay来添加附加物,在OnTap方法中向MapView上添加一个自定义的View(如果已存在就直接设为可见),下面具体来介绍我的实现方法:

一、自定义覆盖物类:MyPopupOverlay,这个类是最关键的一个类ItemizedOverlay,用于设置Marker,并定义Marker的点击事件,弹出窗口,至于弹出窗口的内容,则通过定义Listener,放到Activity中去构造。如果没有特殊需求,这个类不需要做什么改动。代码如下,popupLinear这个对象,就是加到地图上的自定义View:

public class MyPopupOverlay extends ItemizedOverlayOverlayItem {

private Context context = null;

// 这是弹出窗口, 包括内容部分还有下面那个小三角

private LinearLayout popupLinear = null;

// 这是弹出窗口的内容部分

private View popupView = null;

private MapView mapView = null;

private Projection projection = null;

// 这是弹出窗口内容部分使用的layoutId,在Activity中设置

private int layoutId = 0;

// 是否使用百度带有A-J字样的Marker

private boolean useDefaultMarker = false;

private int[] defaultMarkerIds = { R.drawable.icon_marka,

R.drawable.icon_markb, R.drawable.icon_markc,

R.drawable.icon_markd, R.drawable.icon_marke,

R.drawable.icon_markf, R.drawable.icon_markg,

R.drawable.icon_markh, R.drawable.icon_marki,

R.drawable.icon_markj, };

// 这个Listener用于在Marker被点击时让Activity填充PopupView的内容

private OnTapListener onTapListener = null;

public MyPopupOverlay(Context context, Drawable marker, MapView mMapView) {

super(marker, mMapView);

this.context = context;

this.popupLinear = new LinearLayout(context);

this.mapView = mMapView;

popupLinear.setOrientation(LinearLayout.VERTICAL);

popupLinear.setVisibility(View.GONE);

projection = mapView.getProjection();

}

@Override

public boolean onTap(GeoPoint pt, MapView mMapView) {

// 点击窗口以外的区域时,当前窗口关闭

if (popupLinear != null popupLinear.getVisibility() == View.VISIBLE) {

LayoutParams lp = (LayoutParams) popupLinear.getLayoutParams();

Point tapP = new Point();

projection.toPixels(pt, tapP);

Point popP = new Point();

projection.toPixels(lp.point, popP);

int xMin = popP.x - lp.width / 2 + lp.x;

int yMin = popP.y - lp.height + lp.y;

int xMax = popP.x + lp.width / 2 + lp.x;

int yMax = popP.y + lp.y;

if (tapP.x xMin || tapP.y yMin || tapP.x xMax

|| tapP.y yMax)

popupLinear.setVisibility(View.GONE);

}

return false;

}

@Override

protected boolean onTap(int i) {

// 点击Marker时,该Marker滑动到地图中央偏下的位置,并显示Popup窗口

OverlayItem item = getItem(i);

if (popupView == null) {

// 如果popupView还没有创建,则构造popupLinear

if (!createPopupView()){

return true;

}

}

if (onTapListener == null)

return true;

popupLinear.setVisibility(View.VISIBLE);

onTapListener.onTap(i, popupView);

popupLinear.measure(0, 0);

int viewWidth = popupLinear.getMeasuredWidth();

int viewHeight = popupLinear.getMeasuredHeight();

LayoutParams layoutParams = new LayoutParams(viewWidth, viewHeight,

item.getPoint(), 0, -60, LayoutParams.BOTTOM_CENTER);

layoutParams.mode = LayoutParams.MODE_MAP;

popupLinear.setLayoutParams(layoutParams);

Point p = new Point();

projection.toPixels(item.getPoint(), p);

p.y = p.y - viewHeight / 2;

GeoPoint point = projection.fromPixels(p.x, p.y);

mapView.getController().animateTo(point);

return true;

}

private boolean createPopupView() {

// TODO Auto-generated method stub

if (layoutId == 0)

return false;

popupView = LayoutInflater.from(context).inflate(layoutId, null);

popupView.setBackgroundResource(R.drawable.popupborder);

ImageView dialogStyle = new ImageView(context);

dialogStyle.setImageDrawable(context.getResources().getDrawable(

R.drawable.iw_tail));

popupLinear.addView(popupView);

android.widget.LinearLayout.LayoutParams lp = new android.widget.LinearLayout.LayoutParams(

LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);

lp.topMargin = -2;

lp.leftMargin = 60;

popupLinear.addView(dialogStyle, lp);

mapView.addView(popupLinear);

return true;

}

@Override

public void addItem(ListOverlayItem items) {

// TODO Auto-generated method stub

int startIndex = getAllItem().size();

for (OverlayItem item : items){

if (startIndex = defaultMarkerIds.length)

startIndex = defaultMarkerIds.length - 1;

if (useDefaultMarker item.getMarker() == null){

item.setMarker(context.getResources().getDrawable(

defaultMarkerIds[startIndex++]));

}

}

super.addItem(items);

}

@Override

public void addItem(OverlayItem item) {

// TODO Auto-generated method stub

// 重载这两个addItem方法,主要用于设置自己默认的Marker

int index = getAllItem().size();

if (index = defaultMarkerIds.length)

index = defaultMarkerIds.length - 1;

if (useDefaultMarker item.getMarker() == null){

item.setMarker(context.getResources().getDrawable(

defaultMarkerIds[getAllItem().size()]));

}

super.addItem(item);

}

public void setLayoutId(int layoutId) {

this.layoutId = layoutId;

}

public void setUseDefaultMarker(boolean useDefaultMarker) {

this.useDefaultMarker = useDefaultMarker;

}

public void setOnTapListener(OnTapListener onTapListener) {

this.onTapListener = onTapListener;

}

public interface OnTapListener {

public void onTap(int index, View popupView);

}

}

求大神给一份在界面上加载百度地图的代码(不需要其他功能,网上的HELLO ANDROID有问题),不胜感激

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_pubs_info);

title_tv = (TextView) findViewById(R.id.title_text);

title_tv.setText("宾馆");

back_iv = (ImageView) findViewById(R.id.titleleft);

back_iv.setOnClickListener(new OnClickListener() {

@Override

public void onClick(View arg0) {

close();

}

});

search_iv = (ImageView) findViewById(R.id.titlehorse);

search_iv.setOnClickListener(new OnClickListener() {

@Override

public void onClick(View arg0) {

Intent intent = new Intent(Activity_Pubs_listview.this,

PoiSearchActivity.class);

startActivity(intent);

}

});

progressDialog = null;

progressDialog = ProgressDialog.show(Activity_Pubs_listview.this,

"请稍等...", "加载中...", true);

// 初始化MapActivity

mapManager = new BMapManager(getApplication());

// init方法的第一个参数需填入申请的APIKey

mapManager.init(Contants.BAIDUMAPSKEY2, null);

super.initMapActivity(mapManager);

mapView = (MapView) findViewById(R.id.map_View);

// 设置地图模式为交通地图

mapView.setTraffic(true);

// 设置启用内置的缩放控件

mapView.setBuiltInZoomControls(true);

// 设置在缩放动画过程中也显示overlay,默认为不绘制

mapView.setDrawOverlayWhenZooming(true);

// 添加定位图层

mLocationOverlay = new MyLocationOverlay(this, mapView);

mapView.getOverlays().add(mLocationOverlay);

// 注册定位事件

mLocationListener = new LocationListener() {

@Override

public void onLocationChanged(Location location) {

if (location != null) {

geoPoint = new GeoPoint(

(int) (location.getLatitude() * 1e6),

(int) (location.getLongitude() * 1e6));

Log.i("geoPoint", geoPoint.getLatitudeE6() + " "

+ geoPoint.getLongitudeE6());

mapView.getController().animateTo(geoPoint);

mapController = mapView.getController();

// 设置地图的中心

mapController.setCenter(geoPoint);

// 设置地图默认的缩放级别

mapController.setZoom(16);

// 初始化

MKSearch mMKSearch = new MKSearch();

mMKSearch.init(mapManager, new MySearchListener());

// 搜索贵州大学校门口附近500米范围的自动取款机

mMKSearch.poiSearchNearBy("酒店", geoPoint, 500);

}

}

};

如何使用Android调用百度地图API

1.设置定位中心:直接搜索你要找的位置即可。

2.设置地图:设置地图样式,如大小,显示,功能等。

3.添加标注:添加你要标注的地方,自定义坐标位置

4.获取代码:点击获取代码即可,在你要插入百度地图的地方出入百度地图代码

只要插入!--引用百度地图API--部分的代码就行。

关于android百度地图提示框代码和android调用百度地图api的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。

版权说明:如非注明,本站文章均为 AH站长 原创,转载请注明出处和附带本文链接;

本文地址:http://ahzz.com.cn/post/9136.html


取消回复欢迎 发表评论:

分享到

温馨提示

下载成功了么?或者链接失效了?

联系我们反馈

立即下载