宣恩ssl適用于網(wǎng)站、小程序/APP、API接口等需要進(jìn)行數(shù)據(jù)傳輸應(yīng)用場(chǎng)景,ssl證書(shū)未來(lái)市場(chǎng)廣闊!成為成都創(chuàng)新互聯(lián)的ssl證書(shū)銷(xiāo)售渠道,可以享受市場(chǎng)價(jià)格4-6折優(yōu)惠!如果有意向歡迎電話聯(lián)系或者加微信:18982081108(備注:SSL證書(shū)合作)期待與您的合作!
package com.chencheng.meituan.view;
import java.util.ArrayList;
import com.baidu.location.BDLocation;
import com.baidu.location.BDLocationListener;
import com.baidu.location.LocationClient;
import com.baidu.location.LocationClientOption;
import com.baidu.mapapi.map.BaiduMap;
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.MarkerOptions;
import com.baidu.mapapi.map.MyLocationData;
import com.baidu.mapapi.map.OverlayOptions;
import com.baidu.mapapi.model.LatLng;
import com.chencheng.model.Goodlist;
import com.yuchen.meituan.R;
import com.yuchen.meituan.R.id;
import com.yuchen.meituan.R.layout;
import com.yuchen.meituan.R.menu;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;
public class MapActivity extends Activity implements OnClickListener {
public MyLocationListenner myListener = new MyLocationListenner();
private MapView mMapView;
private BaiduMap mBaiduMap;
private LocationClient mLocClient;
boolean isFirstLoc = true;// 是否首次定位
private Goodlist mGoodlist;
BitmapDescriptor bd = BitmapDescriptorFactory
.fromResource(R.drawable.icon_gcoding);
private ArrayList<BitmapDescriptor> mOverLayList = new ArrayList<BitmapDescriptor>();
private double mLng;
private double mLat;
private float scale = 15.0f;
private BDLocation mLocation;
private TextView mTvProduct;
private TextView mTvTitle;
/**
* 定位SDK監(jiān)聽(tīng)函數(shù)
*/
public class MyLocationListenner implements BDLocationListener {
@Override
public void onReceiveLocation(BDLocation location) {
mLocation = location;
// map view 銷(xiāo)毀后不在處理新接收的位置
if (location == null || mMapView == null)
return;
MyLocationData locData = new MyLocationData.Builder()
.accuracy(location.getRadius())
// 此處設(shè)置開(kāi)發(fā)者獲取到的方向信息,順時(shí)針0-360
.direction(100).latitude(location.getLatitude())
.longitude(location.getLongitude()).build();
mBaiduMap.setMyLocationData(locData);
if (isFirstLoc) {
//設(shè)置定位的坐標(biāo)
isFirstLoc = false;
LatLng ll = new LatLng(mLat,mLng);
MapStatusUpdate u = MapStatusUpdateFactory.newLatLng(ll);
//設(shè)置動(dòng)畫(huà)
mBaiduMap.animateMapStatus(u);
}
}
public void onReceivePoi(BDLocation poiLocation) {
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map);
//獲取店鋪?zhàn)鴺?biāo)
mGoodlist = (Goodlist) getIntent().getSerializableExtra("goodsList");
mLng = mGoodlist.getLng();
mLat = mGoodlist.getLat();
initUI();
initMap();
setData();
}
private void setData() {
String product = mGoodlist.getProduct();
String title = mGoodlist.getTitle();
mTvProduct.setText(product);
mTvTitle.setText(title);
}
private void initUI() {
findViewById(R.id.rl_bottom).setOnClickListener(this);
findViewById(R.id.img_add).setOnClickListener(this);
findViewById(R.id.img_reduce).setOnClickListener(this);
findViewById(R.id.img_local).setOnClickListener(this);
findViewById(R.id.rl_back_btn).setOnClickListener(this);
mTvProduct = (TextView) findViewById(R.id.tv_product);
mTvTitle = (TextView) findViewById(R.id.tv_title);
}
@Override
public void onClick(View v) {
MapStatusUpdate msu = null;
switch (v.getId()) {
case R.id.img_add:
//放大
if(scale < 10.0f){
scale = 10.0f;
}
if(scale >= 10.0f && scale <= 20.0f){
scale++;
}
msu = MapStatusUpdateFactory.zoomTo(scale);
mBaiduMap.setMapStatus(msu);
break;
case R.id.img_reduce:
//縮小
if(scale > 20.0f){
scale = 20.0f;
}
if(scale >= 10.0f && scale <= 20.0f){
scale--;
}
msu = MapStatusUpdateFactory.zoomTo(scale);
mBaiduMap.setMapStatus(msu);
break;
case R.id.img_local:
//定位到當(dāng)前位置
LatLng ll = new LatLng(mLocation.getLatitude(),mLocation.getLongitude());
MapStatusUpdate u = MapStatusUpdateFactory.newLatLng(ll);
//設(shè)置動(dòng)畫(huà)
mBaiduMap.animateMapStatus(u);
break;
case R.id.rl_back_btn:
finish();
break;
case R.id.rl_bottom:
//攔截監(jiān)聽(tīng)
break;
default:
break;
}
}
private void initMap() {
// 地圖初始化
mMapView = (MapView) findViewById(R.id.bmapView);
mBaiduMap = mMapView.getMap();
// 設(shè)置比例尺,15.0f(500米),14.0f(1公里),10.0f(20公里)
MapStatusUpdate msu = MapStatusUpdateFactory.zoomTo(scale);
mBaiduMap.setMapStatus(msu);
//添加店鋪?zhàn)鴺?biāo)
addOverlay(mLat, mLng, R.drawable.shop_icon);
// 開(kāi)啟定位圖層
mBaiduMap.setMyLocationEnabled(true);
// 定位初始化
mLocClient = new LocationClient(this);
mLocClient.registerLocationListener(myListener);
LocationClientOption option = new LocationClientOption();
option.setOpenGps(true);// 打開(kāi)gps
option.setCoorType("bd09ll"); // 設(shè)置坐標(biāo)類(lèi)型
option.setScanSpan(1000);
mLocClient.setLocOption(option);
mLocClient.start();
}
private void addOverlay(double lat, double lng, int drawableRes) {
LatLng llA = new LatLng(lat, lng);
//設(shè)置懸浮的圖案
BitmapDescriptor bdA = BitmapDescriptorFactory
.fromResource(drawableRes);
mOverLayList.add(bdA);
OverlayOptions ooA = new MarkerOptions().position(llA).icon(bdA)
.zIndex(9).draggable(true);
//在地圖中添加懸浮圖案
mBaiduMap.addOverlay(ooA);
//設(shè)置懸浮物點(diǎn)擊監(jiān)聽(tīng)
// mBaiduMap.setOnMarkerClickListener(new OnMarkerClickListener() {
// public boolean onMarkerClick(final Marker marker) {
// Button button = new Button(getApplicationContext());
// button.setBackgroundResource(R.drawable.popup);
// button.setText("更改圖標(biāo)");
// button.setOnClickListener(new OnClickListener() {
// public void onClick(View v) {
// marker.setIcon(bd);
// mBaiduMap.hideInfoWindow();
// }
// });
// LatLng ll = marker.getPosition();
// InfoWindow mInfoWindow = new InfoWindow(button, ll, -47);
// mBaiduMap.showInfoWindow(mInfoWindow);
// return true;
// }
// });
}
@Override
protected void onPause() {
mMapView.onPause();
super.onPause();
}
@Override
protected void onResume() {
mMapView.onResume();
super.onResume();
}
@Override
protected void onDestroy() {
mBaiduMap.setMyLocationEnabled(false);
mMapView.onDestroy();
mMapView = null;
super.onDestroy();
for (int i = 0; i < mOverLayList.size(); i++) {
mOverLayList.get(i).recycle();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return false;
}
}
當(dāng)前文章:從json獲取坐標(biāo),生成地圖覆蓋物
分享URL:http://jinyejixie.com/article38/gdpjsp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供營(yíng)銷(xiāo)型網(wǎng)站建設(shè)、外貿(mào)網(wǎng)站建設(shè)、品牌網(wǎng)站制作、網(wǎng)頁(yè)設(shè)計(jì)公司、云服務(wù)器、搜索引擎優(yōu)化
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)