我想买配置比较好的车,是选金杯救护车S70好呢,还是选哈弗H2好呢?

android(9)
利用百度地图 实现QQ/微信发送位置功能
1.看到好多同学 项目需要 模仿发送位置 功能 自己项目也使用了 经过摸索现在分享出来
2.申请百度地图key();
3.主要界面代码 定位界面,内含 一个 popupWindow
里面显示的内容及 发送地图需要的内容 (图片+Location 点及 地点名字address)
package com.
作者 E-mail:
* 创建时间:日 上午11:32:18
import java.io.F
import java.io.FileNotFoundE
import java.io.FileOutputS
import java.io.IOE
import java.io.S
import java.util.ArrayL
import java.util.L
import android.app.A
import android.content.C
import android.content.I
import android.graphics.B
import android.graphics.P
import android.graphics.R
import android.os.B
import android.view.G
import android.view.MotionE
import android.view.V
import android.view.View.OnClickL
import android.view.WindowM
import android.widget.AdapterV
import android.widget.AdapterView.OnItemClickL
import android.widget.ImageB
import android.widget.ImageV
import android.widget.LinearL
import android.widget.LinearLayout.LayoutP
import android.widget.ListV
import android.widget.PopupW
import android.widget.PopupWindow.OnDismissL
import android.widget.ProgressB
import android.widget.TextV
import android.widget.T
import com.baidu.location.BDL
import com.baidu.location.BDLocationL
import com.baidu.location.LocationC
import com.baidu.location.LocationClientO
import com.baidu.mapapi.map.BaiduM
import com.baidu.mapapi.map.BaiduMap.OnMapClickL
import com.baidu.mapapi.map.BaiduMap.OnMapTouchL
import com.baidu.mapapi.map.BaiduMap.SnapshotReadyC
import com.baidu.mapapi.map.BitmapD
import com.baidu.mapapi.map.BitmapDescriptorF
import com.baidu.mapapi.map.MapP
import com.baidu.mapapi.map.MapStatusU
import com.baidu.mapapi.map.MapStatusUpdateF
import com.baidu.mapapi.map.MapV
import com.baidu.mapapi.map.M
import com.baidu.mapapi.map.MarkerO
import com.baidu.mapapi.map.OverlayO
import com.baidu.mapapi.model.LatL
import com.baidu.mapapi.search.core.PoiI
import com.baidu.mapapi.search.core.SearchR
import com.baidu.mapapi.search.geocode.GeoCodeR
import com.baidu.mapapi.search.geocode.GeoC
import com.baidu.mapapi.search.geocode.OnGetGeoCoderResultL
import com.baidu.mapapi.search.geocode.ReverseGeoCodeO
import com.baidu.mapapi.search.geocode.ReverseGeoCodeR
public class MainActivity extends Activity {
MapView mMapV
BaiduMap mBaiduM
ImageView mSelectI
LocationClient mLocationClient = null;
MyBDLocationListner mListner = null;
BitmapDescriptor mCurrentMarker = null;
LatLng mLoactionLatL
boolean isFirstLoc = true;
Point mCenterPoint = null;
GeoCoder mGeoCoder = null;
ListView mListV
PlaceListAdapter mA
List mInfoL
PoiInfo mCurentI
String base64Pic = "";
private ImageButton chat_activity_backB
private TextView placeTv;
private ImageView showI
private PopupWindow mPopupW
* 重要说明
1.本demo 利用百度地图模仿 实现 微信/QQ
发送位置功能
2. 考虑到具体界面比较复杂 所以并未 全仿界面 ,提供实现思路。
3. 拿到demo 后 请从bin 文件中 提取 已经编译好的APK
试看效果。
4. 更换menifast 里面
百度地图 的你自己的 key后
可在本地重新编译 运行
5.百度地图 key申请地址(/apiconsole/key)
mPopupWindow 中显示的内容 即为 要显示在聊天窗口中的内容
包括一张实时 截图 及一个Location 点。
7.如有疑问 可联系QQ:
相互交流学习。
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_chooseplace);
initView();
* 初始化界面
private void initView() {
initPop();
showImg.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this,
PointMapActivity.class);
Location location = new Location();
location.setLatitude(mCurentInfo.location.latitude);
location.setLongitude(mCurentInfo.location.longitude);
location.setAddress(mCurentInfo.address);
intent.putExtra("pointInfo", location);
startActivity(intent);
findViewById(R.id.chat_activity_backBtn).setOnClickListener(
new OnClickListener() {
public void onClick(View v) {
findViewById(R.id.place_btn).setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if (mCurentInfo != null) {
mBaiduMap.snapshot(new SnapshotReadyCallback() {
public void onSnapshotReady(Bitmap snapshot) {
if (mCurentInfo != null) {
mPopupWindow.showAtLocation(getWindow()
.getDecorView(), Gravity.BOTTOM, 0, 0);
showImg.setImageBitmap(snapshot);
placeTv.setText(mCurentInfo.name
+ mCurentInfo.address);
backgroundAlpha(0.1f);
mMapView.setVisibility(View.INVISIBLE);
mMapView = (MapView) findViewById(R.id.chooseplace_bmapView);
mCurrentMarker = BitmapDescriptorFactory
.fromResource(R.drawable.dingwei);
mMapView.showZoomControls(false);
mBaiduMap = mMapView.getMap();
MapStatusUpdate msu = MapStatusUpdateFactory.zoomTo(17.0f);
mBaiduMap.setMapStatus(msu);
mBaiduMap.setOnMapTouchListener(touchListener);
mBaiduMap.setOnMapClickListener(new OnMapClickListener() {
public void onMapClick(LatLng point) {
mLoactionLatLng =
turnBack();
resetMarker(point);
public boolean onMapPoiClick(MapPoi poi) {
return false;
mInfoList = new ArrayList();
mCenterPoint = mBaiduMap.getMapStatus().targetS
mLoactionLatLng = mBaiduMap.getMapStatus().
mBaiduMap.setMyLocationEnabled(true);
mLocationClient = new LocationClient(this);
mListner = new MyBDLocationListner();
mLocationClient.registerLocationListener(mListner);
LocationClientOption option = new LocationClientOption();
option.setOpenGps(true);
option.setCoorType("bd09ll");
option.setScanSpan(0);
mLocationClient.setLocOption(option);
mLocationClient.start();
mGeoCoder = GeoCoder.newInstance();
mGeoCoder.setOnGetGeoCodeResultListener(GeoListener);
mListView = (ListView) findViewById(R.id.place_list);
mListView.setOnItemClickListener(itemClickListener);
mAdapter = new PlaceListAdapter(getLayoutInflater(), mInfoList);
mListView.setAdapter(mAdapter);
mSelectImg = new ImageView(this);
public void backgroundAlpha(float bgAlpha) {
WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.alpha = bgA
getWindow().setAttributes(lp);
private void initPop() {
View view = getLayoutInflater().inflate(R.layout.poup_layout, null);
showImg = (ImageView) view.findViewById(R.id.show_img);
placeTv = (TextView) view.findViewById(R.id.place_tv);
mPopupWindow = showPlaceWindow(view);
mPopupWindow.setOnDismissListener(new OnDismissListener() {
public void onDismiss() {
backgroundAlpha(1.0f);
mMapView.setVisibility(View.VISIBLE);
protected void resetMarker(LatLng point) {
OverlayOptions ooC = new MarkerOptions().position(point)
.icon(mCurrentMarker).zIndex(0);
Marker marker = (Marker) mBaiduMap.addOverlay(ooC);
marker.setPosition(point);
MapStatusUpdate u = MapStatusUpdateFactory.newLatLng(mLoactionLatLng);
mBaiduMap.animateMapStatus(u);
public void turnBack() {
MapStatusUpdate u = MapStatusUpdateFactory.newLatLng(mLoactionLatLng);
mBaiduMap.animateMapStatus(u);
mBaiduMap.clear();
mGeoCoder.reverseGeoCode((new ReverseGeoCodeOption())
.location(mLoactionLatLng));
protected void onDestroy() {
super.onDestroy();
mLocationClient.stop();
mGeoCoder.destroy();
private class MyBDLocationListner implements BDLocationListener {
public void onReceiveLocation(BDLocation location) {
if (location == null || mMapView == null)
mLantitude = location.getLatitude();
mLongtitude = location.getLongitude();
mLoactionLatLng = new LatLng(mLantitude, mLongtitude);
if (isFirstLoc) {
resetMarker(mLoactionLatLng);
isFirstLoc = false;
MapStatusUpdate u = MapStatusUpdateFactory
.newLatLng(mLoactionLatLng);
mBaiduMap.animateMapStatus(u);
mGeoCoder.reverseGeoCode((new ReverseGeoCodeOption())
.location(mLoactionLatLng));
OnGetGeoCoderResultListener GeoListener = new OnGetGeoCoderResultListener() {
public void onGetGeoCodeResult(GeoCodeResult result) {
if (result == null || result.error != SearchResult.ERRORNO.NO_ERROR) {
public void onGetReverseGeoCodeResult(ReverseGeoCodeResult result) {
if (result == null || result.error != SearchResult.ERRORNO.NO_ERROR) {
mCurentInfo = new PoiInfo();
mCurentInfo.address = result.getAddress();
mCurentInfo.location = result.getLocation();
mCurentInfo.name = "[位置]";
mInfoList.clear();
mInfoList.add(mCurentInfo);
if (result.getPoiList() != null) {
mInfoList.addAll(result.getPoiList());
mAdapter.setmList(mInfoList, 0);
OnMapTouchListener touchListener = new OnMapTouchListener() {
public void onTouch(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_UP) {
if (mCenterPoint == null) {
LatLng currentLatL
currentLatLng = mBaiduMap.getProjection().fromScreenLocation(
mCenterPoint);
System.out.println("----" + mCenterPoint.x);
System.out.println("----" + currentLatLng.latitude);
mGeoCoder.reverseGeoCode((new ReverseGeoCodeOption())
.location(currentLatLng));
OnItemClickListener itemClickListener = new OnItemClickListener() {
public void onItemClick(AdapterView parent, View view, int position,
long id) {
mAdapter.setNotifyTip(position);
mBaiduMap.clear();
mCurentInfo = (PoiInfo) mAdapter.getItem(position);
mLoactionLatLng = mCurentInfo.
resetMarker(mLoactionLatLng);
mSelectImg.setBackgroundResource(R.drawable.weigouxuan);
mSelectImg = (ImageView) view.findViewById(R.id.place_select);
mSelectImg.setImageResource(R.drawable.gouxuan);
public PopupWindow showPlaceWindow(View view) {
PopupWindow popupWindow = new PopupWindow(this);
popupWindow.setWidth(LayoutParams.MATCH_PARENT);
popupWindow.setHeight(LayoutParams.WRAP_CONTENT);
popupWindow.setOutsideTouchable(true);
popupWindow.setFocusable(true);
popupWindow.setAnimationStyle(R.anim.push_up_in);
popupWindow.setContentView(view);
return popupW
4.点击popupWindow 跳转到 地图详细界面 pointMapActivity
package com.
import com.baidu.location.BDL
import com.baidu.location.BDLocationL
import com.baidu.location.LocationC
import com.baidu.location.LocationClientO
import com.baidu.mapapi.map.BaiduM
import com.baidu.mapapi.map.BitmapD
import com.baidu.mapapi.map.BitmapDescriptorF
import com.baidu.W
import com.baidu.mapapi.map.MapS
import com.baidu.mapapi.map.MapStatusU
import com.baidu.mapapi.map.MapStatusUpdateF
import com.baidu.mapapi.map.MapV
import com.baidu.mapapi.map.M
import com.baidu.mapapi.map.MarkerO
import com.baidu.mapapi.map.MyLocationC
import com.baidu.mapapi.map.MyLocationD
import com.baidu.mapapi.map.OverlayO
import com.baidu.mapapi.map.BaiduMap.OnMapTouchL
import com.baidu.mapapi.map.MyLocationConfiguration.LocationM
import com.baidu.mapapi.model.LatL
import com.baidu.mapapi.search.core.PoiI
import com.baidu.mapapi.search.core.SearchR
import com.baidu.mapapi.search.geocode.GeoCodeR
import com.baidu.mapapi.search.geocode.GeoC
import com.baidu.mapapi.search.geocode.OnGetGeoCoderResultL
import com.baidu.mapapi.search.geocode.ReverseGeoCodeO
import com.baidu.mapapi.search.geocode.ReverseGeoCodeR
import android.app.A
import android.content.I
import android.graphics.C
import android.graphics.P
import android.os.B
import android.view.MotionE
import android.view.V
import android.view.View.OnClickL
import android.view.ViewGroup.LayoutP
import android.widget.TextV
public class PointMapActivity extends Activity implements OnClickListener {
private MapView mMapV
private BaiduMap mBaiduM
private boolean isFirst = true;
Point mCenterPoint = null;
GeoCoder mGeoCoder = null;
LatLng mLoactionLatL
LocationClient mLocationClient = null;
BitmapDescriptor mCurrentMarker = null;
private boolean isFirstLoc = true;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
initWidget();
public void initWidget() {
setContentView(R.layout.point_activity);
mMapView = (MapView) findViewById(R.id.pointplace_bmapView);
Intent intent = getIntent();
Location location = (Location) intent.getSerializableExtra("pointInfo");
mBaiduMap = mMapView.getMap();
mBaiduMap.setMyLocationEnabled(true);
mCurrentMarker = BitmapDescriptorFactory
.fromResource(R.drawable.dingwei);
mBaiduMap.setMapStatus(MapStatusUpdateFactory
.newMapStatus(new MapStatus.Builder().zoom(17).build()));
mLoactionLatLng = new LatLng(location.getLatitude(),
location.getLongitude());
resetMarker(mLoactionLatLng);
View view = getLayoutInflater().inflate(R.layout.place_layout_tv, null);
TextView tv = (TextView) view.findViewById(R.id.palce_name_tv);
tv.setText(location.getAddress());
mBaiduMap.showInfoWindow(new InfoWindow(view, new LatLng(location
.getLatitude(), location.getLongitude()), -40));
findViewById(R.id.point_back).setOnClickListener(this);
protected void resetMarker(LatLng point) {
OverlayOptions ooC = new MarkerOptions().position(point)
.icon(mCurrentMarker).zIndex(0);
Marker marker = (Marker) mBaiduMap.addOverlay(ooC);
marker.setPosition(point);
MapStatusUpdate u = MapStatusUpdateFactory.newLatLng(mLoactionLatLng);
mBaiduMap.animateMapStatus(u);
public void widgetClick(View v) {
switch (v.getId()) {
case R.id.point_back:
protected void onPause() {
mMapView.onPause();
super.onPause();
protected void onResume() {
mMapView.onResume();
super.onResume();
protected void onDestroy() {
mBaiduMap.setMyLocationEnabled(false);
mMapView.onDestroy();
mMapView = null;
super.onDestroy();
public void onClick(View v) {
widgetClick(v);
5.源码地址OSC:
6.QQ: 欢迎交流
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:3281次
排名:千里之外
原创:11篇
评论:12条
(1)(1)(5)(1)(3)

我要回帖

更多关于 金杯救护车 的文章

 

随机推荐