进气歧管压力传感器在哪里

22137人阅读
(全部源码地址:&&)&
&上篇把界面画出来了, 接下来就是显示里面的功能了,那这篇内容就比较丰富了。
主要有这么几道菜:
1、在地图上弹出泡泡显示信息,并且能相应泡泡的点击时间
2、自动定位当前位置(也就是我的位置) --添加了 GPS定位和基站定位。
3、获取经纬度对应的接到地址名称
那下面就开始代码把,理论知识能讲多少是多少。
一 、 地图弹出泡泡的制作
1 、overlay_popup.xml &直接把layout放出来
&?xml version=&1.0& encoding=&UTF-8&?&
&RelativeLayout xmlns:android=&/apk/res/android&
android:background=&@drawable/bubble_background& android:layout_height=&wrap_content&
android:layout_width=&wrap_content& android:id=&@+id/map_bubblebtn&
android:clickable=&true& android:focusable=&true& android:paddingTop=&5dp&
android:paddingLeft=&5dp& android:paddingRight=&5dp&
android:paddingBottom=&10dp&&
&LinearLayout android:orientation=&vertical& android:id=&@+id/popuptext&
android:layout_width=&wrap_content& android:layout_height=&wrap_content&&
&TextView android:id=&@+id/map_bubbleTitle&
android:ellipsize=&marquee&
android:textSize=&17sp&
android:textColor=&#000000&
android:layout_width=&wrap_content&
android:layout_height=&wrap_content&
android:singleLine=&true&
android:id=&@+id/map_bubbleText&
android:textSize=&14sp&
android:textColor=&#000000&
android:layout_width=&wrap_content&
android:layout_height=&wrap_content&
android:layout_below=&@id/map_bubbleTitle&
&/LinearLayout&
&TextView android:layout_toRightOf=&@id/popuptext& android:layout_width=&wrap_content&
android:layout_height=&wrap_content&
android:background=&@drawable/expander_ic_minimized&
&/RelativeLayout&&
还有泡泡的效果图 ,很多同学做项目都是时间很紧张的,别人贴出来代码都觉得不够直观,有截图是王道,
顺应大部分懒人的习惯,我编截图边发:
看到了吧, 泡泡上有title ,有 desc ,还有一个小icon。我把整个layout 设置成:
android:clickable=&true& android:focusable=&true&
这样这个layout就相当余一个button了,可以点击。
2、那代码怎么实现呢? FzMapActivity里加入下面代码
private void initPopView(){
if(null == popView){
popView = getLayoutInflater().inflate(R.layout.overlay_popup, null);
mapView.addView(popView, new MapView.LayoutParams(
MapView.LayoutParams.WRAP_CONTENT,
MapView.LayoutParams.WRAP_CONTENT, null,
MapView.LayoutParams.BOTTOM_CENTER));
popView.setVisibility(View.GONE);
在进入主界面是 初始化一下view。
private View popV当然这个变量定义也不能少。
3、自定义&itemizedOverlay & & MyItemizedOverlay
好把,先把代码放出来,光描述怎么写太费劲了。
package com.android.fzmap.
import java.util.ArrayL
import java.util.L
import android.content.C
import android.graphics.C
import android.graphics.drawable.D
import android.util.L
import android.view.KeyE
import android.view.V
import android.view.View.OnClickL
import android.widget.RelativeL
import android.widget.TextV
import com.android.fzmap.FzMapA
import com.android.fzmap.R;
import com.google.android.maps.GeoP
import com.google.android.maps.ItemizedO
import com.google.android.maps.MapC
import com.google.android.maps.MapV
import com.google.android.maps.OverlayI
import com.google.android.maps.ItemizedOverlay.OnFocusChangeL
@SuppressWarnings(&rawtypes&)
public class MyItemizedOverlay extends ItemizedOverlay implements OnFocusChangeListener,OnClickListener{
private static final String TAG = &MyItemizedOverlay&;
private List&OverlayItem& overlays = new ArrayList&OverlayItem&();
private FzMapActivity mC
private GeoPoint point =
private String desc = &&;
private String car_title = &&;
private int layout_x = 0; // 用于设置popview 相对某个位置向x轴偏移
private int layout_y = -30; // 用于设置popview 相对某个位置向x轴偏移
private MapView mMapV
private MapController mMapC
private View mPopV
private Drawable itemD
private Drawable itemSelectD
private OverlayItem selectI
private OverlayItem lastI
public void setItemSelectDrawable(Drawable itemSelectDrawable) {
this.itemSelectDrawable = itemSelectD
public MyItemizedOverlay(Drawable defaultMarker) {
super(boundCenterBottom(defaultMarker));
public MyItemizedOverlay(Drawable defaultMarker, Context context, MapView mapView, View popView, MapController mapCtrl) {
super(boundCenterBottom(defaultMarker));
itemDrawable = defaultM
itemSelectDrawable = defaultM
mContext = (FzMapActivity)
setOnFocusChangeListener(this);
layout_x = itemDrawable.getBounds().centerX();
layout_y = - itemDrawable.getBounds().height();
mMapView =
mPopView = popV
mMapCtrl = mapC
protected OverlayItem createItem(int i) {
return overlays.get(i);
public int size() {
return overlays.size();
public void addOverlay(OverlayItem item) {
overlays.add(item);
populate();
public void removeOverlay(int location) {
overlays.remove(location);
public boolean onTap(GeoPoint p, MapView mapView) {
return super.onTap(p, mapView);
protected boolean onTap(int index) {
return super.onTap(index);
public void draw(Canvas canvas, MapView mapView, boolean shadow) {
super.draw(canvas, mapView, shadow);
public void onFocusChanged(ItemizedOverlay overlay, OverlayItem newFocus) {
Log.d(TAG , &item focus changed!&);
if (null != newFocus) {
Log.d(TAG , &centerY : & + itemDrawable.getBounds().centerY() + &; centerX :& + itemDrawable.getBounds().centerX());
Log.d(TAG , & height : & + itemDrawable.getBounds().height());
MapView.LayoutParams params = (MapView.LayoutParams) mPopView.getLayoutParams();
params.x = this.layout_x;//Y轴偏移
params.y = this.layout_y;//Y轴偏移
point = newFocus.getPoint();
params.point =
mMapCtrl.animateTo(point);
TextView title_TextView = (TextView) mPopView.findViewById(R.id.map_bubbleTitle);
title_TextView.setText(newFocus.getTitle());
TextView desc_TextView = (TextView) mPopView.findViewById(R.id.map_bubbleText);
if(null == newFocus.getSnippet() || &&.equals(newFocus.getSnippet())){
desc_TextView.setVisibility(View.GONE);
this.desc = newFocus.getSnippet();
desc_TextView.setText(this.desc);
desc_TextView.setVisibility(View.VISIBLE);
RelativeLayout button = (RelativeLayout) mPopView.findViewById(R.id.map_bubblebtn);
button.setOnClickListener(this);
mMapView.updateViewLayout(mPopView, params);
mPopView.setVisibility(View.VISIBLE);
selectItem = newF
public void onClick(View v) {
switch (v.getId()) {
主要是继承 &OnFocusChangeListener &监听地图层的变化, 为了方便监听button事件也继承了OnClickListener。
下面这方法监听这个层改变的时间,把泡泡弹出来。&
public void onFocusChanged(ItemizedOverlay overlay, OverlayItem newFocus) {
Log.d(TAG , &item focus changed!&);
if (null != newFocus) {
Log.d(TAG , &centerY : & + itemDrawable.getBounds().centerY() + &; centerX :& + itemDrawable.getBounds().centerX());
Log.d(TAG , & height : & + itemDrawable.getBounds().height());
MapView.LayoutParams params = (MapView.LayoutParams) mPopView.getLayoutParams();
params.x = this.layout_x;//Y轴偏移
params.y = this.layout_y;//Y轴偏移
point = newFocus.getPoint();
params.point =
mMapCtrl.animateTo(point);
TextView title_TextView = (TextView) mPopView.findViewById(R.id.map_bubbleTitle);
title_TextView.setText(newFocus.getTitle());
TextView desc_TextView = (TextView) mPopView.findViewById(R.id.map_bubbleText);
if(null == newFocus.getSnippet() || &&.equals(newFocus.getSnippet())){
desc_TextView.setVisibility(View.GONE);
desc = newFocus.getSnippet();
desc_TextView.setText(desc);
desc_TextView.setVisibility(View.VISIBLE);
RelativeLayout button = (RelativeLayout) mPopView.findViewById(R.id.map_bubblebtn);
button.setOnClickListener(this);
mMapView.updateViewLayout(mPopView, params);
mPopView.setVisibility(View.VISIBLE);
selectItem = newF
二、长按地图获取地图位置并弹出泡泡显示信息
它的继承关系 &LongPressOverlay extends Overlay implements OnDoubleTapListener
LongPressOverlay这个层主要是用来接收长按事件 和双击地图界面的
package com.android.fzmap.
import android.os.H
import android.view.GestureD
import android.view.GestureDetector.OnDoubleTapL
import android.view.GestureDetector.OnGestureL
import android.view.MotionE
import com.android.fzmap.FzMapA
import com.google.android.maps.MapC
import com.google.android.maps.MapV
import com.google.android.maps.O
public class LongPressOverlay extends Overlay implements OnDoubleTapListener,OnGestureListener{
private FzMapActivity mC
private MapView mMapV
private Handler mH
private MapController mMapC
private GestureDetector gestureScanner = new GestureDetector(this);
private int level = 0;
public LongPressOverlay(FzMapActivity context, MapView mapView, Handler handler,MapController mapCtrl){
mContext =
mMapView = mapV
mHandler =
mMapCtrl = mapC
public boolean onTouchEvent(MotionEvent event, MapView mapView) {
return gestureScanner.onTouchEvent(event);
public boolean onSingleTapConfirmed(MotionEvent e) {
public boolean onDoubleTap(MotionEvent e) {
public boolean onDoubleTapEvent(MotionEvent e) {
if(++level % 3 == 0){
mMapCtrl.zoomIn();
level = 0;
public boolean onDown(MotionEvent e) {
public void onShowPress(MotionEvent e) {
public boolean onSingleTapUp(MotionEvent e) {
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
float distanceY) {
public void onLongPress(MotionEvent e) {
mContext.locPoint = mMapView.getProjection().fromPixels((int) e.getX(),
(int) e.getY());
mHandler.sendEmptyMessage(mContext.MSG_VIEW_LONGPRESS);
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
&@Override
public void onLongPress(MotionEvent e) {
mContext.locPoint = mMapView.getProjection().fromPixels((int) e.getX(),
(int) e.getY());
mHandler.sendEmptyMessage(mContext.MSG_VIEW_LONGPRESS);
}接收到长按事件后给主界面发消息,由主界面处理。
三、FzLocationManager 这个类用来做gps,基站定位
package com.android.fzmap.
import android.content.C
import android.location.L
import android.location.LocationL
import android.location.LocationM
import android.os.B
import android.util.L
* @author why
public class FzLocationManager {
private final String TAG = &FzLocationManager&;
private static Context mC
private LocationManager gpsLocationM
private LocationManager networkLocationM
private static final int MINTIME = 2000;
private static final int MININSTANCE = 2;
private static FzLocationM
private Location lastLocation =
private static LocationCallBack mC
public static void init(Context c , LocationCallBack callback) {
mContext =
mCallback =
private FzLocationManager() {
// Gps 定位
gpsLocationManager = (LocationManager) mContext
.getSystemService(Context.LOCATION_SERVICE);
Location gpsLocation = gpsLocationManager
.getLastKnownLocation(LocationManager.GPS_PROVIDER);
gpsLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,
MINTIME, MININSTANCE, locationListener);
// 基站定位
networkLocationManager = (LocationManager) mContext
.getSystemService(Context.LOCATION_SERVICE);
Location networkLocation = gpsLocationManager
.getLastKnownLocation(LocationManager.GPS_PROVIDER);
networkLocationManager.requestLocationUpdates(
LocationManager.NETWORK_PROVIDER, MINTIME, MININSTANCE,
locationListener);
public static FzLocationManager getInstance() {
if (null == instance) {
instance = new FzLocationManager();
private void updateLocation(Location location) {
lastLocation =
mCallback.onCurrentLocation(location);
private final LocationListener locationListener = new LocationListener() {
public void onStatusChanged(String provider, int status, Bundle extras) {
public void onProviderEnabled(String provider) {
public void onProviderDisabled(String provider) {
public void onLocationChanged(Location location) {
Log.d(TAG, &onLocationChanged&);
updateLocation(location);
public Location getMyLocation() {
return lastL
private static int ENOUGH_LONG = 1000 * 60;
public interface LocationCallBack{
* 当前位置
* @param location
void onCurrentLocation(Location location);
public void destoryLocationManager(){
Log.d(TAG, &destoryLocationManager&);
gpsLocationManager.removeUpdates(locationListener);
networkLocationManager.removeUpdates(locationListener);
public interface LocationCallBack{
* 当前位置
* @param location&
void onCurrentLocation(Location location);
定义一个接口 ,当监听到位置变化时,回调主界面
//locationListener注册监听器到位置服务管理里
networkLocationManager.requestLocationUpdates(
LocationManager.NETWORK_PROVIDER, MINTIME, MININSTANCE,
locationListener);
//位置信息变化回调
private void updateLocation(Location location) {
lastLocation =
mCallback.onCurrentLocation(location);
四、主界面逻辑
package com.android.
import java.io.IOE
import java.util.L
import java.util.L
import android.graphics.drawable.D
import android.location.A
import android.location.G
import android.location.L
import android.os.B
import android.os.H
import android.os.M
import android.util.L
import android.view.V
import android.view.View.OnClickL
import android.view.W
import android.widget.ImageB
import android.widget.TextV
import com.android.fzmap.map.FzLocationM
import com.android.fzmap.map.FzLocationManager.LocationCallB
import com.android.fzmap.map.LongPressO
import com.android.fzmap.map.MyItemizedO
import com.google.android.maps.GeoP
import com.google.android.maps.MapA
import com.google.android.maps.MapC
import com.google.android.maps.MapV
import com.google.android.maps.O
import com.google.android.maps.OverlayI
import com.android.fzmap.R;
public class FzMapActivity
extends MapActivity implements LocationCallBack ,OnClickListener{
/** Called when the activity is first created. */
private final String TAG = &FzMapActivity&;
private MapView mapV
private MapController mMapC
private View popV
private Drawable myLocationD
private Drawable mylongPressD
private FzLocationManager fzL
private MyItemizedOverlay myLocationO
private MyItemizedOverlay mLongPressO
private List&Overlay& mapO
private OverlayItem overlayitem =
public GeoPoint locP
ImageButton loction_B
ImageButton layer_B
ImageButton pointwhat_B
public final int MSG_VIEW_LONGPRESS = 10001;
public final int MSG_VIEW_ADDRESSNAME = 10002;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
loction_Btn = (ImageButton)findViewById(R.id.loction);
layer_Btn = (ImageButton)findViewById(R.id.layer);
pointwhat_Btn = (ImageButton)findViewById(R.id.pointwhat);
loction_Btn.setOnClickListener(this);
layer_Btn.setOnClickListener(this);
pointwhat_Btn.setOnClickListener(this);
myLocationDrawable = getResources().getDrawable(R.drawable.point_where);
mylongPressDrawable = getResources().getDrawable(R.drawable.point_start);
mapView = (MapView) findViewById(R.id.map_view);
mapView.setBuiltInZoomControls(true);
mapView.setClickable(true);
initPopView();
mMapCtrl = mapView.getController();
myLocationOverlay = new MyItemizedOverlay(myLocationDrawable,this, mapView, popView, mMapCtrl);
mLongPressOverlay = new MyItemizedOverlay(mylongPressDrawable,this, mapView, popView, mMapCtrl);
mapOverlays = mapView.getOverlays();
mapOverlays.add(new LongPressOverlay(this, mapView, mHandler, mMapCtrl));
//以北京市中心为中心
GeoPoint cityLocPoint = new GeoPoint(6397428);
mMapCtrl.animateTo(cityLocPoint);
mMapCtrl.setZoom(12);
FzLocationManager.init(FzMapActivity.this.getApplicationContext() , FzMapActivity.this);
fzLocation = FzLocationManager.getInstance();
private void initPopView(){
if(null == popView){
popView = getLayoutInflater().inflate(R.layout.overlay_popup, null);
mapView.addView(popView, new MapView.LayoutParams(
MapView.LayoutParams.WRAP_CONTENT,
MapView.LayoutParams.WRAP_CONTENT, null,
MapView.LayoutParams.BOTTOM_CENTER));
popView.setVisibility(View.GONE);
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
public void onCurrentLocation(Location location) {
Log.d(TAG, &onCurrentLocationy&);
GeoPoint point = new GeoPoint(
(int) (location.getLatitude() * 1E6),
(int) (location.getLongitude() * 1E6));
overlayitem = new OverlayItem(point, &我的位置&, &&);
mMapCtrl.setZoom(16);
if(myLocationOverlay.size() & 0){
myLocationOverlay.removeOverlay(0);
myLocationOverlay.addOverlay(overlayitem);
mapOverlays.add(myLocationOverlay);
mMapCtrl.animateTo(point);
private String getLocationAddress(GeoPoint point){
String add = &&;
Geocoder geoCoder = new Geocoder(getBaseContext(),
Locale.getDefault());
List&Address& addresses = geoCoder.getFromLocation(
point.getLatitudeE6() / 1E6, point.getLongitudeE6() / 1E6, 1);
Address address = addresses.get(0);
int maxLine = address.getMaxAddressLineIndex();
if(maxLine &= 2){
address.getAddressLine(1) + address.getAddressLine(2);
add = address.getAddressLine(1);
} catch (IOException e) {
e.printStackTrace();
Runnable getAddressName = new Runnable() {
public void run() {
String addressName = &&;
while(true){
addressName = getLocationAddress(locPoint);
Log.d(TAG, &获取地址名称&);
if(!&&.equals(addressName)){
Message msg = new Message();
msg.what = MSG_VIEW_ADDRESSNAME;
msg.obj = addressN
mHandler.sendMessage(msg);
private Handler mHandler = new Handler() {
public void handleMessage(Message msg) {
switch (msg.what) {
case MSG_VIEW_LONGPRESS:
if(null == locPoint)
new Thread(getAddressName).start();
overlayitem = new OverlayItem(locPoint, &地址名称&,
&正在地址加载...&);
if(mLongPressOverlay.size() & 0){
mLongPressOverlay.removeOverlay(0);
popView.setVisibility(View.GONE);
mLongPressOverlay.addOverlay(overlayitem);
mLongPressOverlay.setFocus(overlayitem);
mapOverlays.add(mLongPressOverlay);
mMapCtrl.animateTo(locPoint);
mapView.invalidate();
case MSG_VIEW_ADDRESSNAME:
TextView desc = (TextView) popView.findViewById(R.id.map_bubbleText);
desc.setText((String)msg.obj);
popView.setVisibility(View.VISIBLE);
public void onClick(View v) {
switch (v.getId()) {
case R.id.loction:
protected void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
fzLocation.destoryLocationManager();
部分注释写在代码里了
最后再上一张截图,在室内通过基站定位到我的位置:
五、通过经纬度获取地址
这个单独拷贝出来让大家看看。这个方法获取地址有时候获取不到的,google好像对这个接口有限制。说白了就这这个接口不靠谱。
大家可以尝试用别的方法或手段获取地址
我的代码里加了个死循环去获取位置,这样的方案是不可取的,不过暂时用一下看看效果也好。
*&通过经纬度获取地址
* @param point
private String getLocationAddress(GeoPoint point){
String add = &&;
Geocoder geoCoder = new Geocoder(getBaseContext(),
Locale.getDefault());
List&Address& addresses = geoCoder.getFromLocation(
point.getLatitudeE6() / 1E6, point.getLongitudeE6() / 1E6, 1);
Address address = addresses.get(0);
int maxLine = address.getMaxAddressLineIndex();
if(maxLine &= 2){
add = &address.getAddressLine(1) + address.getAddressLine(2);
add = address.getAddressLine(1);
} catch (IOException e) {
e.printStackTrace();
好了,以上是所有代码, &AndroidManifest.xml 在 &(一)里有。
用google的api获取到的位置放到他的地图上是有偏差的,而且偏差还比不小,大家可以观察一下,这个问题没有很好的免费解决方案。
如果有哪位有什么好建议可以发出来,谢谢。
用基站和gps定位,也没有处理那个是更好的定位的问题。
欢迎大家提建议
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:2097250次
积分:14054
积分:14054
排名:第254名
原创:120篇
转载:14篇
评论:1092条
阅读:54742
文章:15篇
阅读:445788
文章:17篇
阅读:193638
文章:31篇
阅读:867238
(3)(2)(1)(2)(1)(1)(2)(2)(3)(5)(1)(7)(2)(5)(10)(4)(7)(4)(13)(27)(5)(1)(1)(1)(1)(1)(3)(1)(7)(1)(3)(4)(4)您好!欢迎来到中国制造网
经营模式:生产制造
所在地区:浙江省&
认证信息:
您当前访问的产品需要授权才能查看,请尝试用密码访问或索取密码。
密码:确定北京协和医院地址,电话,位置地图、怎么走?_好大夫在线
咨询专家:
好大夫在线提供的是医患沟通平台,医生使用这个平台为患者提供基于病情的建议,而非诊疗
当前位置: &
& 地址地图
010-114(预约挂号),010-(总机),010-(东院咨询台),010-(西院咨询台)
东城区东单帅府园1号(东院);西城区大木仓胡同41号(西院)
东院行车路线(外地患者):从北京站出发:乘坐103路、104路在新东安市场下车,步行至医院;从北京西站出发:乘52路在东单路口西下车,或者去1号线军事博物馆站乘地铁到东单站下车,步行至医院;(本地患者):乘坐公交106路、108路、111路、110路在东单下车,步行至医院,或者乘坐地铁1号线、5号线东单站下车;
西院行车路线(外地患者):从北京站出发,乘地铁2号线在宣武门下车,换乘15路在民族文化宫下车,步行至西院;从北京西站出发,乘54路在长椿街路口东换乘10路,在民族文化宫下车,步行至西院;(本地患者):乘坐7路、10路、15路、37路、88路、90路、205路在民族文化宫下车,步行至西院.
终点:北京协和医院&&
向好大夫咨询
近2周回复279问
咨询范围:硬皮病,性病,湿疹,银屑病,痤疮,白...
近2周回复248问
咨询范围:不孕不育、绝经、多囊卵巢综合征、月经...
近2周回复211问
咨询范围:垂体腺瘤,胶质瘤、脑膜瘤等颅内肿瘤,...
近2周回复156问
咨询范围:性病, 皮炎湿疹银屑病, 脱发
近2周回复155问
咨询范围:宫颈癌前病变、子宫肌瘤、子宫腺肌症、...
近2周回复145问
咨询范围:白血病,淋巴瘤,骨髓瘤,Castleman病,P...
近2周回复140问
咨询范围:因时间有限,仅处理在我这里就诊过的风...
近2周回复137问
咨询范围:各种常见皮肤病
近2周回复118问
咨询范围:乳腺可疑或确诊乳腺恶性病变;乳腺良性...
近2周回复104问
咨询范围:宫颈机能不全,盆腔器官脱垂,子宫剖宫...
提示:任何关于疾病的建议都不能替代执业医师的面对面诊断。所有门诊时间仅供参考,最终以医院当日公布为准。网友、医生言论仅代表其个人观点,不代表本站同意其说法,请谨慎参阅,本站不承担由此引起的法律责任。
北京市公安局朝阳分局备案编号:
好大夫在线版权所有 Copyright 2014

我要回帖

更多关于 进气歧管压力传感器 的文章

 

随机推荐