真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網站制作重慶分公司

從json獲取坐標,生成地圖覆蓋物

從json獲取坐標,生成地圖覆蓋物

宣恩ssl適用于網站、小程序/APP、API接口等需要進行數據傳輸應用場景,ssl證書未來市場廣闊!成為成都創(chuàng)新互聯(lián)的ssl證書銷售渠道,可以享受市場價格4-6折優(yōu)惠!如果有意向歡迎電話聯(lián)系或者加微信:18982081108(備注:SSL證書合作)期待與您的合作!

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 mOverLayList = new ArrayList();

private double mLng;

private double mLat;

private float scale = 15.0f;

private BDLocation mLocation;

private TextView mTvProduct;

private TextView mTvTitle;

/**

* 定位SDK監(jiān)聽函數

*/

public class MyLocationListenner implements BDLocationListener {

@Override

public void onReceiveLocation(BDLocation location) {

mLocation = location;

// map view 銷毀后不在處理新接收的位置

if (location == null || mMapView == null)

return;

MyLocationData locData = new MyLocationData.Builder()

.accuracy(location.getRadius())

// 此處設置開發(fā)者獲取到的方向信息,順時針0-360

.direction(100).latitude(location.getLatitude())

.longitude(location.getLongitude()).build();

mBaiduMap.setMyLocationData(locData);

if (isFirstLoc) {

//設置定位的坐標

isFirstLoc = false;

LatLng ll = new LatLng(mLat,mLng);

MapStatusUpdate u = MapStatusUpdateFactory.newLatLng(ll);

//設置動畫

mBaiduMap.animateMapStatus(u);

}

}

public void onReceivePoi(BDLocation poiLocation) {

}

}

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_map);

//獲取店鋪坐標

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:

//定位到當前位置

LatLng ll = new LatLng(mLocation.getLatitude(),mLocation.getLongitude());

MapStatusUpdate u = MapStatusUpdateFactory.newLatLng(ll);

//設置動畫

mBaiduMap.animateMapStatus(u);

break;

case R.id.rl_back_btn:

finish();

break;

case R.id.rl_bottom:

//攔截監(jiān)聽

break;

default:

break;

}

}

private void initMap() {

// 地圖初始化

mMapView = (MapView) findViewById(R.id.bmapView);

mBaiduMap = mMapView.getMap();

// 設置比例尺,15.0f(500米),14.0f(1公里),10.0f(20公里)

MapStatusUpdate msu = MapStatusUpdateFactory.zoomTo(scale);

mBaiduMap.setMapStatus(msu);

//添加店鋪坐標

addOverlay(mLat, mLng, R.drawable.shop_icon);

// 開啟定位圖層

mBaiduMap.setMyLocationEnabled(true);

// 定位初始化

mLocClient = new LocationClient(this);

mLocClient.registerLocationListener(myListener);

LocationClientOption option = new LocationClientOption();

option.setOpenGps(true);// 打開gps

option.setCoorType("bd09ll"); // 設置坐標類型

option.setScanSpan(1000);

mLocClient.setLocOption(option);

mLocClient.start();

}

private void addOverlay(double lat, double lng, int drawableRes) {

LatLng llA = new LatLng(lat, lng);

//設置懸浮的圖案

BitmapDescriptor bdA = BitmapDescriptorFactory

.fromResource(drawableRes);

mOverLayList.add(bdA);

OverlayOptions ooA = new MarkerOptions().position(llA).icon(bdA)

.zIndex(9).draggable(true);

//在地圖中添加懸浮圖案

mBaiduMap.addOverlay(ooA);

//設置懸浮物點擊監(jiān)聽

// mBaiduMap.setOnMarkerClickListener(new OnMarkerClickListener() {

// public boolean onMarkerClick(final Marker marker) {

// Button button = new Button(getApplicationContext());

// button.setBackgroundResource(R.drawable.popup);

// button.setText("更改圖標");

// 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;

}

}


新聞名稱:從json獲取坐標,生成地圖覆蓋物
URL網址:http://weahome.cn/article/gdpjsp.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部