android自定义地图
㈠ android 中如何隐藏google地图上自定义绘制的图标
我觉着可以让那个按钮在鼠标或是手指碰触的时候,显示相应的信息或是功能,不适用的时候(也就是不碰触的时候)让他变成透明的按钮,在成寻中用代码控制就可以了....
㈡ Android上怎么实现百度地图自定义图层,如下图所示
有个tileoverlay,可以把瓦片叠加在地图上。但是你这个截图比较像游戏地图,网络地图目前没有游戏行业解决方案,高德地图有。
㈢ 高德地图android开发,怎样自定义线路,根据
亲亲,您可以点击进入高德官网首页--开放平台--控制台--工单--创建工单哦。
㈣ android地图,怎么添加自定义InfoWindow
使用swift来使用高德地图,这里使用Android实践高德地图包含定位,移动地图动画,获取网络数据,marker标记以及点击,Infowindow自定义界面以及点击,以及点击无marker地图上面隐藏infowindow等功能。直接看代码
[java] view plain print?
package com.carmap.ui;
import android.graphics.Color;
import android.location.Location;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import com.amap.api.location.AMapLocation;
import com.amap.api.location.AMapLocationListener;
import com.amap.api.location.LocationManagerProxy;
import com.amap.api.location.LocationProviderProxy;
import com.amap.api.maps.AMap;
import com.amap.api.maps.AMap.InfoWindowAdapter;
import com.amap.api.maps.AMap.OnCameraChangeListener;
import com.amap.api.maps.AMap.OnInfoWindowClickListener;
import com.amap.api.maps.AMap.OnMapClickListener;
import com.amap.api.maps.AMap.OnMapLoadedListener;
import com.amap.api.maps.AMap.OnMarkerClickListener;
import com.amap.api.maps.CameraUpdateFactory;
import com.amap.api.maps.LocationSource;
import com.amap.api.maps.MapView;
import com.amap.api.maps.UiSettings;
import com.amap.api.maps.model.BitmapDescriptorFactory;
import com.amap.api.maps.model.CameraPosition;
import com.amap.api.maps.model.LatLng;
import com.amap.api.maps.model.Marker;
import com.amap.api.maps.model.MarkerOptions;
import com.amap.api.maps.model.MyLocationStyle;
import com.carmap.R;
import com.carmap.ui.base.BaseActivity;
/**
*
* @author jwzhangjie
*
*/
public class MapActivity extends BaseActivity implements AMapLocationListener,
LocationSource, OnMarkerClickListener, OnInfoWindowClickListener,
InfoWindowAdapter, OnMapLoadedListener, OnCameraChangeListener,
AnimationListener, OnClickListener, OnMapClickListener {
private MapView mapView;
private AMap aMap;
private LocationManagerProxy aMapManager;
private OnLocationChangedListener mListener;
private UiSettings mUiSettings;
private AMapLocation aLocation;
private Animation centerMarker;
private ImageView centerImageView;
private Marker currentMarker;
private boolean isFirst = true;
private ImageView locate;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map);
mapView = (MapView) findViewById(R.id.mapView);
mapView.onCreate(savedInstanceState);// 此方法必须重写
centerMarker = AnimationUtils.loadAnimation(this,
R.anim.center_map_bounds);
centerImageView = (ImageView) findViewById(R.id.centerMarkerImg);
locate = (ImageView) findViewById(R.id.locate);
initMap();
}
/**
* 初始化AMap对象
*/
private void initMap() {
if (aMap == null) {
aMap = mapView.getMap();
mUiSettings = aMap.getUiSettings();
}
// 自定义系统定位小蓝点
MyLocationStyle myLocationStyle = new MyLocationStyle();
myLocationStyle.myLocationIcon(BitmapDescriptorFactory
.fromResource(R.drawable.transdrawable));// 设置小蓝点的图标
myLocationStyle.strokeColor(Color.argb(0, 0, 0, 0));// 设置圆形的边框颜色
myLocationStyle.radiusFillColor(Color.argb(0, 0, 0, 0));// 设置圆形的填充颜色
myLocationStyle.strokeWidth(0f);// 设置圆形的边框粗细
aMap.setMyLocationStyle(myLocationStyle);
aMap.setMyLocationRotateAngle(180);
aMap.setLocationSource(this);// 设置定位监听
mUiSettings.setMyLocationButtonEnabled(false); // 是否显示默认的定位按钮
aMap.setMyLocationEnabled(true);// 是否可触发定位并显示定位层
aMap.setMyLocationType(AMap.LOCATION_TYPE_LOCATE);
mUiSettings.setTiltGesturesEnabled(false);// 设置地图是否可以倾斜
mUiSettings.setScaleControlsEnabled(true);// 设置地图默认的比例尺是否显示
mUiSettings.setZoomControlsEnabled(false);
initMapListener();
}
private void initMapListener() {
aMap.setOnMapLoadedListener(this);
aMap.setOnCameraChangeListener(this);
aMap.setOnMarkerClickListener(this);
aMap.setOnInfoWindowClickListener(this);
aMap.setInfoWindowAdapter(this);// 设置自定义InfoWindow样式
aMap.setOnMapClickListener(this);
centerMarker.setAnimationListener(this);
locate.setOnClickListener(this);
}
/**
* 方法必须重写
*/
@Override
protected void onResume() {
super.onResume();
mapView.onResume();
}
/**
* 方法必须重写
*/
@Override
protected void onPause() {
super.onPause();
mapView.onPause();
}
/**
* 方法必须重写
*/
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
mapView.onSaveInstanceState(outState);
}
/**
* 方法必须重写
*/
@Override
protected void onDestroy() {
super.onDestroy();
mapView.onDestroy();
}
@Override
public void onLocationChanged(Location location) {
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
@Override
public void onProviderEnabled(String provider) {
}
@Override
public void onProviderDisabled(String provider) {
}
@Override
public void onLocationChanged(AMapLocation aLocation) {
if (aLocation != null) {
this.aLocation = aLocation;
if (mListener != null)
mListener.onLocationChanged(aLocation);// 显示系统小蓝点
if (isFirst) {
isFirst = false;
aMap.moveCamera(CameraUpdateFactory.changeLatLng(new LatLng(
aLocation.getLatitude(), aLocation.getLongitude())));
CameraUpdateFactory.zoomTo(16);
MarkerOptions markerOption = new MarkerOptions();
markerOption.position(new LatLng(aLocation.getLatitude(),
aLocation.getLongitude()));
markerOption.title("上海市").snippet("上海:34.341568, 108.940174");
markerOption.draggable(true);
Marker marker = aMap.addMarker(markerOption);
marker.setObject("11");//这里可以存储用户数据
}
}
}
@SuppressWarnings("deprecation")
@Override
public void activate(OnLocationChangedListener listener) {
mListener = listener;
if (aMapManager == null) {
aMapManager = LocationManagerProxy.getInstance(this);
/*
* 1.0.2版本新增方法,设置true表示混合定位中包含gps定位,false表示纯网络定位,默认是true
*/
// Location API定位采用GPS和网络混合定位方式,时间最短是2000毫秒
aMapManager.requestLocationUpdates(
LocationProviderProxy.AMapNetwork, 2000, 10, this);
}
}
/**
* 停止定位
*/
@Override
public void deactivate() {
mListener = null;
if (aMapManager != null) {
aMapManager.removeUpdates(this);
aMapManager.destory();
}
aMapManager = null;
}
@Override
public boolean onMarkerClick(Marker marker) {
currentMarker = marker;
Log.e("marker", marker.getObject() + "marker: " + marker.getPosition().latitude+" : "+marker);
return false;
}
@Override
public View getInfoContents(Marker marker) {
Log.e("marker",
marker.getObject() + "getInfoContents: " + marker.getId());
return null;
}
@Override
public View getInfoWindow(Marker marker) {
Log.e("marker", marker.getObject() + "getInfoWindow: " + marker.getId());
View infoWindow = getLayoutInflater().inflate(
R.layout.custom_info_window, null);
render(marker, infoWindow);
return infoWindow;
}
@Override
public void onInfoWindowClick(Marker marker) {
Log.e("marker",
marker.getObject() + "onInfoWindowClick: " + marker.getId());
}
@Override
public void onMapLoaded() {
centerImageView.startAnimation(centerMarker);
CameraUpdateFactory.zoomTo(16);
Log.e("load", "onMapLoaded");
}
@Override
public void onCameraChange(CameraPosition arg0) {
}
@Override
public void onCameraChangeFinish(CameraPosition arg0) {
centerImageView.startAnimation(centerMarker);
Log.e("load", "onCameraChangeFinish+获取后台数据");
}
@Override
public void onAnimationStart(Animation animation) {
centerImageView.setImageResource(R.drawable.green_pin_lift);
}
@Override
public void onAnimationRepeat(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
centerImageView.setImageResource(R.drawable.green_pin);
}
㈤ 高德android导航开发,要怎么自定义路线。。
目前高德地图里自定义路线还不完善,现在只可以设置3个点。一个是起点,一个是途经点,还有一个是终点,我之前也是想设计自定义路线,发现设不设都无所谓,你怎么走系统都会为你规划到正确的路线上。你用高德地图走习惯了,他也有记忆功能,知道你平时喜欢走的路线,以后就会按你习惯的路线进行规划路线了。希望能帮到你。
㈥ android开发百度地图怎么实现自定义弹出窗口
基本原理就是用ItemizedOverlay来添加附加物,在OnTap方法中向MapView上添加一个自定义的View(如果已存在就直接设为可见),下面具体来介绍我的实现方法:
一、自定义覆盖物类:MyPopupOverlay,这个类是最关键的一个类ItemizedOverlay,用于设置Marker,并定义Marker的点击事件,弹出窗口,至于弹出窗口的内容,则通过定义Listener,放到Activity中去构造。如果没有特殊需求,这个类不需要做什么改动。代码如下,popupLinear这个对象,就是加到地图上的自定义View:
public class MyPopupOverlay extends ItemizedOverlay<OverlayItem> {
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(List<OverlayItem> 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);
}
}
㈦ android开发 百度地图3.0以上版本,如何显示自定义标记图标
//定义Maker坐标点
LatLng point = new LatLng(39.963175, 116.400244);
//构建Marker图标
BitmapDescriptor bitmap = BitmapDescriptorFactory
.fromResource(R.drawable.icon_marka);
//构建MarkerOption,用于在地图上添加Marker
OverlayOptions option = new MarkerOptions()
.position(point)
.icon(bitmap);
//在地图上添加Marker,并显示
mBaiMap.addOverlay(option);
㈧ 如何为google map v3 android客户端 自定义地图放大缩小控件
google map 有自带的放大缩小控件,,但我想自己更改其显示样式和位置,,请问怎么做??望各位大侠告知!!!
㈨ android怎么样开发地图定位使用自己重绘的地图
开玩笑,自己做地图……你有测绘资质么?你有海量遥感影像和一个庞大的地图数据制作基地么?你有切割好的现成地图瓦片么?你精通横轴墨卡托投影和各种测量坐标之间的转换么?
最多只能根据当前缩放级别和中心点从Google 或的地图服务器上下载现成的地图瓦片,然后自己拼接绘制而已,怎么样保证地图瓦片的高效提供是一个难题,瓦片地图的各种转换算法又是一个难题?
图样图僧破,骚年
㈩ android使用百度地图3.0版本怎样实现自定义弹出窗口功能
基本原理就是用ItemizedOverlay来添加附加物,在OnTap方法中向MapView上添加一个自定义的View(如果已存在就直接设为可见),下面具体来介绍我的实现方法:
一、自定义覆盖物类:MyPopupOverlay,这个类是最关键的一个类ItemizedOverlay,用于设置Marker,并定义Marker的点击事件,弹出窗口,至于弹出窗口的内容,则通过定义Listener,放到Activity中去构造。如果没有特殊需求,这个类不需要做什么改动。代码如下,popupLinear这个对象,就是加到地图上的自定义View:
<OverlayItem>{
privateContextcontext=null;
//这是弹出窗口,包括内容部分还有下面那个小三角
=null;
//这是弹出窗口的内容部分
private
ViewpopupView=null;
privateMapViewmapView=null;
private
Projectionprojection=null;
//这是弹出窗口内容部分使用的layoutId,在Activity中设置
privateintlayoutId=
0;
//是否使用网络带有A-J字样的Marker
=
false;
privateint[]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
OnTapListeneronTapListener=null;
publicMyPopupOverlay(Contextcontext,Drawablemarker,MapViewmMapView)
{
super(marker,mMapView);
this.context=
context;
this.popupLinear=newLinearLayout(context);
this.mapView=mMapView;
popupLinear.setOrientation(LinearLayout.VERTICAL);
popupLinear.setVisibility(View.GONE);
projection=
mapView.getProjection();
}
@Override
publicbooleanonTap(GeoPointpt,MapViewmMapView)
{
//点击窗口以外的区域时,当前窗口关闭
if(popupLinear!=null&&
popupLinear.getVisibility()==View.VISIBLE){
LayoutParamslp=
(LayoutParams)popupLinear.getLayoutParams();
PointtapP=new
Point();
projection.toPixels(pt,tapP);
PointpopP
=newPoint();
projection.toPixels(lp.point,
popP);
intxMin=popP.x-lp.width/2+lp.x;
intyMin=popP.y-lp.height+lp.y;
intxMax=popP.x+
lp.width/2+lp.x;
intyMax=popP.y+lp.y;
if
(tapP.x<xMin||tapP.y<yMin||tapP.x>xMax
||tapP.y>yMax)
popupLinear.setVisibility(View.GONE);
}
return
false;
}
@Override
protectedbooleanonTap(inti){
//
点击Marker时,该Marker滑动到地图中央偏下的位置,并显示Popup窗口
OverlayItemitem=
getItem(i);
if(popupView==null){
//
如果popupView还没有创建,则构造popupLinear
if
(!createPopupView()){
returntrue;
}
}
if(onTapListener==null)
return
true;
popupLinear.setVisibility(View.VISIBLE);
onTapListener.onTap(i,popupView);
popupLinear.measure(0,0);
intviewWidth=
popupLinear.getMeasuredWidth();
intviewHeight=
popupLinear.getMeasuredHeight();
LayoutParamslayoutParams=newLayoutParams(viewWidth,
viewHeight,
item.getPoint(),0,-60,
LayoutParams.BOTTOM_CENTER);
layoutParams.mode=
LayoutParams.MODE_MAP;
popupLinear.setLayoutParams(layoutParams);
Pointp=new
Point();
projection.toPixels(item.getPoint(),p);
p.y=
p.y-viewHeight/2;
GeoPointpoint=projection.fromPixels(p.x,
p.y);
mapView.getController().animateTo(point);
return
true;
}
privatebooleancreatePopupView(){
//TODOAuto-generated
methodstub
if(layoutId==0)
return
false;
popupView=LayoutInflater.from(context).inflate(layoutId,
null);
popupView.setBackgroundResource(R.drawable.popupborder);
ImageView
dialogStyle=newImageView(context);
dialogStyle.setImageDrawable(context.getResources().getDrawable(
R.drawable.iw_tail));
popupLinear.addView(popupView);
android.widget.LinearLayout.LayoutParamslp=new
android.widget.LinearLayout.LayoutParams(
LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT);
lp.topMargin=
-2;
lp.leftMargin=60;
popupLinear.addView(dialogStyle,
lp);
mapView.addView(popupLinear);
returntrue;
}
@Override
publicvoidaddItem(List<OverlayItem>items)
{
//TODOAuto-generatedmethodstub
intstartIndex=
getAllItem().size();
for(OverlayItemitem: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
publicvoidaddItem(OverlayItemitem){
//
TODOAuto-generatedmethodstub
//
重载这两个addItem方法,主要用于设置自己默认的Marker
intindex=
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);
}
publicvoidsetLayoutId(intlayoutId){
this.layoutId=
layoutId;
}
publicvoidsetUseDefaultMarker(booleanuseDefaultMarker){
this.useDefaultMarker=useDefaultMarker;
}
publicvoidsetOnTapListener(OnTapListeneronTapListener){
this.onTapListener=onTapListener;
}
publicinterfaceOnTapListener{
publicvoidonTap(intindex,
ViewpopupView);
}
}
二、MainActivity,这是主界面,用来显示地图,创建MyPopupOverlay对象,在使用我写的MyPopupOverlay这个类时,需要遵循以下步骤:
创建MyPopupOverlay对象,构造函数为public MyPopupOverlay(Context context, Drawable marker, MapView mMapView),四个参数分别为当前的上下文、通用的Marker(这是ItemizedOverlay需要的,当不设置Marker时的默认Marker)以及网络地图对象。
设置自定义的弹出窗口内容的布局文件ID,使用的方法为public void setLayoutId(int layoutId)。
设置是使用自定义的Marker,还是预先写好的带有A-J字样的网络地图原装Marker,使用的方法为public void setUseDefaultMarker(boolean useDefaultMarker),只有当这个值为true且没有调用OverlayItem的setMarker方法为特定点设置Marker时,才使用原装Marker。
创建Marker所在的点,即分别创建一个个OverlayItem,然后调用public void addItem(OverlayItem item)或public void addItem(List<OverlayItem> items)方法来把这些OverlayItem添加到自定义的附加层上去。
为MyPopupOverlay对象添加onTap事件,当Marker被点击时,填充弹出窗口中的内容(也就是第2条中layoutId布局中的内容),设置方法为public void setOnTapListener(OnTapListener onTapListener),OnTapListener是定义在MyPopupOverlay中的接口,实现这个接口需要覆写public void onTap(int index, View popupView)方法,其中,index表示被点击的Marker(确切地说是OverlayItem)的索引,popupView是使用layoutId这个布局的View,也就是弹出窗口除了下面的小三角之外的部分。
把这个MyPopupOverlay对象添加到地图上去:mMapView.getOverlays().add(myOverlay);mMapView.refresh();