百度地图开发-将多个地点标记在地图上,点击节点弹出PopupWindow
2020-12-13 15:57
标签:安卓 android 百度地图 最近在写一个安卓程序,用到了百度地图API的一些内容,就随便玩耍了一下。 这个DEMO是用来将多个地点标记在地图上,然后点击节点弹出PopupWindow 下面是一些截图: main.xml
popupwindow_showlocations.xml
百度地图开发-将多个地点标记在地图上,点击节点弹出PopupWindow 标签:安卓 android 百度地图 原文地址:http://blog.csdn.net/luoyhang003/article/details/40842931

import com.baidu.mapapi.SDKInitializer;
import com.baidu.mapapi.map.BaiduMap;
import com.baidu.mapapi.map.BaiduMap.OnMarkerClickListener;
import com.baidu.mapapi.map.BitmapDescriptor;
import com.baidu.mapapi.map.BitmapDescriptorFactory;
import com.baidu.mapapi.map.MapStatusUpdate;
import com.baidu.mapapi.map.MapStatusUpdateFactory;
import com.baidu.mapapi.map.MapView;
import com.baidu.mapapi.map.Marker;
import com.baidu.mapapi.map.MarkerOptions;
import com.baidu.mapapi.map.OverlayOptions;
import com.baidu.mapapi.model.LatLng;
import com.baidu.mapapi.model.LatLngBounds;
import android.support.v7.app.ActionBarActivity;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.PopupWindow;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends ActionBarActivity {
private MapView mMapView;
private BaiduMap mBaiduMap;
private Marker marker[];
private TextView locationName;
private TextView locationTime;
private PopupWindow infoPopupWindow;
BitmapDescriptor bitmapDescriptor;
BitmapDescriptor bdGround;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SDKInitializer.initialize(getApplicationContext());
setContentView(R.layout.layout_showlocations);
locationName = (TextView)findViewById(R.id.tv_locationname);
locationTime = (TextView)findViewById(R.id.tv_locationtime);
LayoutInflater layoutInflater = (LayoutInflater)this.getSystemService(LAYOUT_INFLATER_SERVICE);
View popupWindow = layoutInflater.inflate(R.layout.popupwindow_showlocations, null);
infoPopupWindow = new PopupWindow(popupWindow, 600, 800);
infoPopupWindow.setFocusable(true);
infoPopupWindow.setBackgroundDrawable(new BitmapDrawable());
locationName = (TextView)popupWindow.findViewById(R.id.tv_locationname);
locationTime = (TextView)popupWindow.findViewById(R.id.tv_locationtime);
final LocationOfPhoto locations[] = new LocationOfPhoto[4];
locations[0] = new LocationOfPhoto("齐鲁软件学院", "2013.06.06", 36.673141, 117.114275);
locations[1] = new LocationOfPhoto("天安门", "2014.06.06", 39.912089, 116.403928);
locations[2] = new LocationOfPhoto("五大道", "2013.04.02", 39.116073, 117.203932);
locations[3] = new LocationOfPhoto("甘肃白银", "2013.04.02", 36.501821, 104.205648);
mMapView = (MapView)findViewById(R.id.bmapView);
mBaiduMap = mMapView.getMap();
bitmapDescriptor = BitmapDescriptorFactory.fromResource(R.drawable.icon_gcoding);
bdGround = BitmapDescriptorFactory.fromResource(R.drawable.icon_gcoding);
initOverlay(locations);
mBaiduMap.setOnMarkerClickListener(new OnMarkerClickListener() {
@Override
public boolean onMarkerClick(Marker m) {
for(int index = 0; index
LocationOfPhoto.java
import com.baidu.mapapi.model.LatLng;
public class LocationOfPhoto {
private String name;
private String time;
private LatLng location;
public LocationOfPhoto() {
name = "";
time = "";
location = null;
}
public LocationOfPhoto(String name, String time, LatLng location){
this.name = name;
this.time = time;
this.location = location;
}
public LocationOfPhoto(String name, String time, double latitude, double longitude){
this.name = name;
this.time = time;
location = new LatLng(latitude, longitude);
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* @return the time
*/
public String getTime() {
return time;
}
/**
* @param time the time to set
*/
public void setTime(String time) {
this.time = time;
}
/**
* @return the location
*/
public LatLng getLocation() {
return location;
}
/**
* @param location the location to set
*/
public void setLocation(LatLng location) {
this.location = location;
}
}
文章标题:百度地图开发-将多个地点标记在地图上,点击节点弹出PopupWindow
文章链接:http://soscw.com/essay/35573.html