|
package com.electric.chargingpile.activity;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import com.amap.api.location.AMapLocation;
import com.amap.api.location.AMapLocationClient;
import com.amap.api.location.AMapLocationClientOption;
import com.amap.api.location.AMapLocationListener;
import com.amap.api.maps.AMap;
import com.amap.api.maps.CameraUpdateFactory;
import com.amap.api.maps.LocationSource;
import com.amap.api.maps.MapView;
import com.amap.api.maps.UiSettings;
import com.amap.api.maps.model.BitmapDescriptor;
import com.amap.api.maps.model.BitmapDescriptorFactory;
import com.amap.api.maps.model.CameraPosition;
import com.amap.api.maps.model.LatLng;
import com.amap.api.maps.model.Marker;
import com.amap.api.maps.model.MarkerOptions;
import com.amap.api.maps.model.MyLocationStyle;
import com.amap.api.services.core.LatLonPoint;
import com.amap.api.services.geocoder.GeocodeResult;
import com.amap.api.services.geocoder.GeocodeSearch;
import com.amap.api.services.geocoder.RegeocodeQuery;
import com.amap.api.services.geocoder.RegeocodeResult;
import com.electric.chargingpile.R;
import com.electric.chargingpile.application.MainApplication;
import com.electric.chargingpile.data.User;
import com.electric.chargingpile.data.Zhan;
import com.electric.chargingpile.util.BarColorUtil;
import com.electric.chargingpile.util.DES3;
import com.electric.chargingpile.util.NetUtil;
import com.electric.chargingpile.util.OkHttpUtil;
import com.electric.chargingpile.util.Util;
import com.electric.chargingpile.view.CustomProgressDialog;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.Response;
import com.umeng.analytics.MobclickAgent;
import org.json.JSONException;
import org.json.JSONObject;
import java.net.URLEncoder;
import java.text.DecimalFormat;
//位置信息错误界面
public class AlterTwoActivity extends Activity implements
OnClickListener, GeocodeSearch.OnGeocodeSearchListener, AMap.OnCameraChangeListener, AMap.OnMapLoadedListener, LocationSource, AMap.InfoWindowAdapter, AMapLocationListener {
private ImageView ivBack;
private TextView ivNext;
// LocationClient mLocClient;
// public MyLocationListenner myListener = new MyLocationListenner();
// private LocationMode mCurrentMode;
private BitmapDescriptor bdLocation = BitmapDescriptorFactory
.fromResource(R.drawable.icon_zhen2_0);
private BitmapDescriptor bdLocation1 = BitmapDescriptorFactory
.fromResource(R.drawable.icon_bgreen);
private Marker mMarker;
private Marker mMarker1;
// private InfoWindow mInfoWindow;
private TextView tv_one_introduce, tv_submit;
private ImageView iv_alter;
public static LatLng center = null;
// MapView mMapView;
// BaiduMap mBaiduMap;
// private MapStatus mapStatus;
User user;
OnCheckedChangeListener radioButtonListener;
Button requestLocButton;
// boolean isFirstLoc = true;// 是否首次定位
private Zhan zhan;
private String zhan_id, poi_jing, poi_wei, zhan_name;
private Context mContext;
BitmapDescriptor mCurrentMarker;
private static boolean isGetData = false;
// GeoCoder mSearch = null;
public static LatLng llposition = null;
private static String location;
private static String city;
private static String district;
LatLng selectedCenter = null;
private EditText et_address, et_remark;
private CustomProgressDialog pd_info;
private RelativeLayout tv_citynotice;
private ImageButton ib_loaction, ib_add, ib_jian;
private float minZoomLevel;
private float maxZoomLevel;
TextView tv;
TextView tv1;
private Toast toast = null;
private String gd_jing, gd_wei;
private String et_phone, et_name, fast_num, slow_num, open_object, charge_cost, park_cost, other_cost,
charge_style, park_style, other_style, open_time, close_time, holiday_open, holiday_close,
operation_state, suit_car, belong_state;
private MapView mapView;
private AMap aMap;
private UiSettings mUiSettings;
private AMapLocationClient mlocationClient;
private LocationSource.OnLocationChangedListener mListener;
private AMapLocationClientOption mLocationOption;
private GeocodeSearch geocoderSearch;
boolean isFirstLoc = true; // 是否首次定位
private ImageView inBtn, outBtn;
private String zhan_address;
private boolean isFirst = false;
private String original_jing, original_wei, change_jing, change_wei;
private boolean first_tag = true;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_alter_two);
BarColorUtil.initStatusBarColor(AlterTwoActivity.this);
mapView = (MapView) findViewById(R.id.mapView);
mapView.onCreate(savedInstanceState);
mContext = this;
initView();
initMap();
}
private void initView() {
tv_citynotice = (RelativeLayout) findViewById(R.id.tv_citynotice);
tv_citynotice.setVisibility(View.VISIBLE);
tv_citynotice.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
tv_citynotice.setVisibility(View.GONE);
}
});
et_remark = (EditText) findViewById(R.id.et_remark);
ivBack = (ImageView) findViewById(R.id.iv_back);
ivBack.setOnClickListener(this);
et_address = (EditText) findViewById(R.id.et_address);
tv_submit = (TextView) findViewById(R.id.tv_submit);
tv_submit.setOnClickListener(this);
inBtn = (ImageView) findViewById(R.id.zoomin1);
outBtn = (ImageView) findViewById(R.id.zoomout1);
inBtn.setOnClickListener(this);
outBtn.setOnClickListener(this);
// zhan = (Zhan) getIntent().getSerializableExtra("zhan");
zhan_id = getIntent().getStringExtra("zhanid");
poi_jing = getIntent().getStringExtra("jing");
poi_wei = getIntent().getStringExtra("wei");
original_jing = roundByScale(Double.parseDouble(poi_jing), 5);
original_wei = roundByScale(Double.parseDouble(poi_wei), 5);
Log.e("poi_jing", poi_jing);
Log.e("original_jing", original_jing);
Log.e("poi_wei", poi_wei);
Log.e("original_wei", original_wei);
zhan_name = getIntent().getStringExtra("zhanname");
zhan_address = getIntent().getStringExtra("zhanaddress");
et_address.setText(zhan_address);
// ib_add = (ImageButton) findViewById(R.id.icon_jia);
// ib_add.setOnClickListener(this);
//
// ib_jian = (ImageButton) findViewById(R.id.icon_jian);
// ib_jian.setOnClickListener(this);
ib_loaction = (ImageButton) findViewById(R.id.ib_location);
ib_loaction.setOnClickListener(this);
// iv_alter = (ImageView) findViewById(R.id.iv_alter);
// iv_alter.setOnClickListener(this);
// mMapView = (MapView) findViewById(R.id.mapView_share);
// mBaiduMap = mMapView.getMap();
//// mMapView.showZoomControls(false);
// mBaiduMap.setMapStatus(MapStatusUpdateFactory
// .newMapStatus(new MapStatus.Builder().zoom(15f).build()));
// mBaiduMap.setMyLocationEnabled(true);
// mBaiduMap.setOnMapClickListener(new OnMapClickListener() {
//
// @Override
// public boolean onMapPoiClick(MapPoi poi) {
// llposition = poi.getPosition();
// initOverlay1();
// return false;
// }
//
// @Override
// public void onMapClick(LatLng point) {
// llposition = point;
//// if(mMarker != null){
//// mMarker.remove();
//// }
//// mBaiduMap.clear();
//// OverlayOptions oobd1 = new MarkerOptions().position(llposition)
//// .icon(bdLocation).zIndex(9).draggable(true);
//// mMarker1 = (Marker) (mBaiduMap.addOverlay(oobd1));
//// tv1 = new TextView(getApplication());
//// tv1.setBackgroundResource(R.drawable.bg_myinfowindow2_0);
//// tv1.setPadding(12, 12, 12, 12);
//// tv1.setGravity(View.TEXT_ALIGNMENT_CENTER);
//// tv1.setText(location);
//// tv1.setTextColor(getResources().getColor(R.color.hintColor));
//// tv1.setTextSize(15);
//// mInfoWindow = new InfoWindow(tv, llposition, -130);
//// mBaiduMap.showInfoWindow(mInfoWindow);
// initOverlay1();
// getAddress();
// }
// });
// mLocClient = new LocationClient(this);
// mLocClient.registerLocationListener(myListener);
// LocationClientOption option = new LocationClientOption();
// option.setOpenGps(true);
// option.setCoorType("bd09ll");
// option.setScanSpan(1000);
// mLocClient.setLocOption(option);
// mLocClient.start();
// fast_num,slow_num,open_object,charge_cost,park_cost,other_cost,
// charge_style,park_style,other_style,open_time,close_time,holiday_open,holiday_close;
// et_name=getIntent().getStringExtra("et_name");
// et_phone = getIntent().getStringExtra("et_phone");
// fast_num = getIntent().getStringExtra("fast_num");
// slow_num = getIntent().getStringExtra("slow_num");
// open_object = getIntent().getStringExtra("open_object");
// charge_cost = getIntent().getStringExtra("charge_cost");
// park_cost = getIntent().getStringExtra("park_cost");
// other_cost =getIntent().getStringExtra("other_cost");
// charge_style = getIntent().getStringExtra("charge_style");
// park_style = getIntent().getStringExtra("park_style");
// other_style = getIntent().getStringExtra("other_style");
// open_time = getIntent().getStringExtra("open_time");
// close_time = getIntent().getStringExtra("close_time");
// holiday_open = getIntent().getStringExtra("holiday_open");
// holiday_close = getIntent().getStringExtra("holiday_close");
// operation_state = getIntent().getStringExtra("tv_operation_state");
// belong_state = getIntent().getStringExtra("tv_belong_detail");
// suit_car = getIntent().getStringExtra("tv_suit_detail");
}
public void initOverlay() {
aMap.clear();
MarkerOptions oobd = new MarkerOptions().position(llposition)
.icon(bdLocation1).zIndex(9).draggable(true).title(zhan_name).period(30);
mMarker = (Marker) (aMap.addMarker(oobd));
mMarker.showInfoWindow();
}
public void initOverlay1() {
aMap.clear();
MarkerOptions oobd1 = new MarkerOptions().position(llposition)
.icon(bdLocation).zIndex(9).draggable(true).title(zhan_name);
mMarker1 = (Marker) (aMap.addMarker(oobd1));
mMarker1.showInfoWindow();
getAddress(new LatLonPoint(llposition.latitude, llposition.longitude));
}
public void getAddress(final LatLonPoint latLonPoint) {
RegeocodeQuery query = new RegeocodeQuery(latLonPoint, 200,
GeocodeSearch.AMAP);// 第一个参数表示一个Latlng,第二参数表示范围多少米,第三个参数表示是火系坐标系还是GPS原生坐标系
geocoderSearch.getFromLocationAsyn(query);// 设置同步逆地理编码请求
}
//
// @Override
// public void onGetGeoCodeResult(GeoCodeResult result) {
//
// }
//
// @Override
// public void onGetReverseGeoCodeResult(ReverseGeoCodeResult result) {
// if (result == null || result.error != SearchResult.ERRORNO.NO_ERROR) {
// Toast.makeText(AlterTwoActivity.this, "抱歉,未能找到结果",
// Toast.LENGTH_LONG).show();
// return;
// }
// location = result.getAddress();
// city = Util.getCityName(result.getAddress());
//
//
// tv = new TextView(this);
// tv.setBackgroundResource(R.drawable.bg_myinfowindow2_0);
// tv.setPadding(4,0,4,16);
// tv.setGravity(Gravity.CENTER);
//
// if(mMarker != null){
// tv.setText(zhan_name);
// et_address.setText(zhan_name);
// }
// if (mMarker1 != null){
// tv.setText(location);
// et_address.setText(location);
// }
//// tv.setGravity(View.TEXT_ALIGNMENT_CENTER);
//
// tv.setTextColor(getResources().getColor(R.color.hintColor));
// tv.setTextSize(15);
// mInfoWindow = new InfoWindow(tv, llposition, -130);
// mBaiduMap.showInfoWindow(mInfoWindow);
//
//
// }
public void createDialog() {
if (pd_info == null) {
pd_info = CustomProgressDialog.createDialog(mContext);
pd_info.setMessage(mContext.getResources().getString(
R.string.version_updating));
pd_info.show();
}
}
public void dismissDialog() {
if (pd_info != null) {
pd_info.dismiss();
pd_info = null;
}
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.iv_back:
finish();
break;
case R.id.tv_one_introduce:
startActivity(new Intent(this, AlterOneActivity.class));
break;
case R.id.tv_submit:
createDialog();
new Thread(new Runnable() {
@Override
public void run() {
submit();
}
}).start();
break;
case R.id.zoomin1:
aMap.moveCamera(CameraUpdateFactory.zoomIn());
controlZoomShow();
break;
case R.id.zoomout1:
aMap.moveCamera(CameraUpdateFactory.zoomOut());
controlZoomShow();
break;
case R.id.ib_location:
if (!isFirstLoc) {
aMap.setMyLocationEnabled(true);// 设置为true表示显示定位层并可触发定位,false表示隐藏定位层并不可触发定位,默认是false
// 设置定位的类型为定位模式 ,可以由定位、跟随或地图根据面向方向旋转几种
aMap.setMyLocationType(AMap.LOCATION_TYPE_LOCATE);
// aMap.moveCamera();
aMap.moveCamera(CameraUpdateFactory.zoomTo(16));
mlocationClient.startLocation();
}
break;
case R.id.tv_three_other:
if (TextUtils.isEmpty(location)) {
Toast.makeText(this, "正在获取您的位置信息", Toast.LENGTH_SHORT).show();
} else {
}
break;
}
}
//地图缩放方法
private void controlZoomShow() {
float zoom = aMap.getCameraPosition().zoom;
try {
if (zoom >= maxZoomLevel) {
inBtn.setImageResource(R.drawable.icon_nojia2_0);
inBtn.setEnabled(false);
return;
} else {
inBtn.setImageResource(R.drawable.icon_jia2_0);
inBtn.setEnabled(true);
}
if (zoom <= minZoomLevel) {
outBtn.setImageResource(R.drawable.icon_nojian2_0);
outBtn.setEnabled(false);
return;
} else {
outBtn.setImageResource(R.drawable.icon_jian2_0);
outBtn.setEnabled(true);
}
} catch (Exception e) {
e.printStackTrace();
}
}
private Handler handler = new Handler() {
// 主线程通过这个方法处理消息
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case 2:
JSONObject jsonObj = null;
try {
jsonObj = new JSONObject(msg.obj.toString());
String rtnCode = jsonObj.getString("rtnCode");
String rtnMsg = jsonObj.getString("rtnMsg");
Log.e("位置纠错模块测试", rtnMsg);
if (rtnCode.equals("01")) {
dismissDialog();
Toast.makeText(AlterTwoActivity.this, "感谢您的纠错,我们会尽快审核您提供的充电站信息", Toast.LENGTH_SHORT).show();
tv_submit.setEnabled(true);
finish();
} else {
dismissDialog();
Toast.makeText(AlterTwoActivity.this, "失败提交", Toast.LENGTH_SHORT).show();
tv_submit.setEnabled(true);
}
} catch (JSONException e) {
e.printStackTrace();
}
case 3:
break;
default:
break;
}
}
};
private void showTextToast(String msg) {
if (toast == null) {
toast = Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_SHORT);
} else {
toast.setText(msg);
}
toast.show();
}
public static String roundByScale(double v, int scale) {
if (scale < 0) {
throw new IllegalArgumentException(
"The scale must be a positive integer or zero");
}
if (scale == 0) {
return new DecimalFormat("0").format(v);
}
String formatStr = "0.";
for (int i = 0; i < scale; i++) {
formatStr = formatStr + "0";
}
return new DecimalFormat(formatStr).format(v);
}
private void submit() {
if (!NetUtil.CheckNetwork(this)) {
Toast.makeText(this, "请检查网络", Toast.LENGTH_SHORT).show();
return;
}
long appTime1 = System.currentTimeMillis() / 1000;
Log.i("appTime(long)---", appTime1 + "");
long updatetime = appTime1 - MainMapActivity.cha - 1;
String token = String.valueOf(updatetime);
Request request = null;
try {
String jing = roundByScale(Double.parseDouble(poi_jing), 16);
String wei = roundByScale(Double.parseDouble(poi_wei), 16);
request = new Request.Builder().url(MainApplication.url + "/zhannew/basic/web/index.php/zhanalterpoi/add?poi_jing=" + jing + "&poi_wei=" + wei + "&user_id=" + MainApplication.userId + "&zhan_id=" + zhan_id + "&contact=" + URLEncoder.encode(et_remark.getText().toString()) + "&token=" + URLEncoder.encode(DES3.encode(token)) + "&zhan_address=" + et_address.getText().toString()).build();
} catch (Exception e) {
e.printStackTrace();
}
Response response = null;
try {
response = OkHttpUtil.execute(request);
if (response.code() == 200) {
String json = "";
try {
json = response.body().string();
Message msg = new Message();
msg.obj = json;
msg.what = 2;
handler.sendMessage(msg);
Log.e("url", json);
} catch (Exception e) {
e.printStackTrace();
Message msg = new Message();
msg.what = 3;
handler.sendMessage(msg);
}
}
} catch (Exception e) {
e.printStackTrace();
Message msg = new Message();
msg.what = 3;
handler.sendMessage(msg);
}
}
@Override
protected void onPause() {
mapView.onPause();
super.onPause();
MobclickAgent.onPause(this);
}
@Override
protected void onResume() {
mapView.onResume();
super.onResume();
MobclickAgent.onResume(this);
}
@Override
protected void onDestroy() {
mapView.onDestroy();
super.onDestroy();
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
mapView.onSaveInstanceState(outState);
}
private void initMap() {
if (aMap == null) {
aMap = mapView.getMap();
Util.setMapCustomStyleFile(aMap, getApplicationContext());
MyLocationStyle myLocationStyle = new MyLocationStyle();
myLocationStyle.myLocationIcon(com.amap.api.maps.model.BitmapDescriptorFactory
.fromResource(R.drawable.point_icon));// 设置小蓝点的图标
aMap.setMyLocationStyle(myLocationStyle);
mUiSettings = aMap.getUiSettings();
//获得地图的最大和最小缩放级别
maxZoomLevel = aMap.getMaxZoomLevel();
minZoomLevel = aMap.getMinZoomLevel();
geocoderSearch = new GeocodeSearch(this);
geocoderSearch.setOnGeocodeSearchListener(this);
setUpMap();
}
}
private void setUpMap() {
aMap.setOnCameraChangeListener(this);
aMap.setLocationSource(this);// 设置定位监听
aMap.setOnMapLoadedListener(this);
aMap.setInfoWindowAdapter(this);
// aMap.setOnMapClickListener(this);
aMap.getUiSettings().setMyLocationButtonEnabled(false);// 设置默认定位按钮是否显示
aMap.getUiSettings().setZoomControlsEnabled(false);// 设置默认缩放按钮是否显示
aMap.getUiSettings().setScaleControlsEnabled(true);// 设置比例尺是否显示
aMap.getUiSettings().setRotateGesturesEnabled(false);// 设置地图是否旋转
}
@Override
public void onRegeocodeSearched(RegeocodeResult result, int i) {
if (i == 1000) {
if (result != null && result.getRegeocodeAddress() != null
&& result.getRegeocodeAddress().getFormatAddress() != null) {
if (isFirst == false) {
et_address.setText(zhan_address);
isFirst = true;
} else {
zhan_address = result.getRegeocodeAddress().getFormatAddress();
et_address.setText(zhan_address);
if (!change_jing.equals(original_jing) && !change_wei.equals(original_wei)) {
tv_submit.setEnabled(true);
tv_submit.setClickable(true);
tv_submit.setBackgroundResource(R.color.lvse);
}
}
// tv_submit.setBackgroundColor(getResources().getColor(R.color.lvse));
// tv_submit.setClickable(true);
}
}
}
@Override
public void onGeocodeSearched(GeocodeResult geocodeResult, int i) {
}
@Override
public void onCameraChange(CameraPosition cameraPosition) {
et_address.setText("正在获取位置,请您耐心等待...");
tv_submit.setBackgroundColor(getResources().getColor(R.color.huise));
tv_submit.setClickable(false);
}
@Override
public void onCameraChangeFinish(CameraPosition cameraPosition) {
controlZoomShow();
LatLng target = cameraPosition.target;
getAddress(new LatLonPoint(target.latitude, target.longitude));
poi_jing = String.valueOf(target.longitude);
poi_wei = String.valueOf(target.latitude);
change_jing = roundByScale(target.longitude, 5);
change_wei = roundByScale(target.latitude, 5);
}
@Override
public void onMapLoaded() {
aMap.setMyLocationEnabled(true);// 设置为true表示显示定位层并可触发定位,false表示隐藏定位层并不可触发定位,默认是false
// 设置定位的类型为定位模式 ,可以由定位、跟随或地图根据面向方向旋转几种
aMap.setMyLocationType(AMap.LOCATION_TYPE_LOCATE);
aMap.moveCamera(CameraUpdateFactory.zoomTo(16));
int position_jing = poi_jing.length() - poi_jing.indexOf(".") + 1;
int position_wei = poi_wei.length() - poi_wei.indexOf(".") + 1;
LatLng ll;
if (position_jing > 13 || position_wei > 13) {
ll = new LatLng(Double.parseDouble(poi_wei), Double.parseDouble(poi_jing));
} else {
getGaode(Double.parseDouble(poi_jing), Double.parseDouble(poi_wei));
ll = new LatLng(Double.parseDouble(gd_wei), Double.parseDouble(gd_jing));
}
llposition = ll;
//设置缩放级别
aMap.moveCamera(CameraUpdateFactory.zoomTo(16));
//将地图移动到定位点
aMap.moveCamera(CameraUpdateFactory.changeLatLng(llposition));
// initOverlay();
}
private void getGaode(Double jing, Double wei) {
double x_pi = 3.14159265358979324 * 3000.0 / 180.0;
double gg_lon;
double gg_lat;
double x = jing - 0.0065, y = wei - 0.006;
double z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * x_pi);
double theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * x_pi);
gg_lon = z * Math.cos(theta);
gd_jing = String.valueOf(gg_lon);
gg_lat = z * Math.sin(theta);
gd_wei = String.valueOf(gg_lat);
}
@Override
public void activate(OnLocationChangedListener onLocationChangedListener) {
mListener = onLocationChangedListener;
if (mlocationClient == null) {
mlocationClient = new AMapLocationClient(this);
mLocationOption = new AMapLocationClientOption();
//设置定位监听
mlocationClient.setLocationListener(this);
//设置为高精度定位模式
mLocationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);
//设置定位参数
mlocationClient.setLocationOption(mLocationOption);
// 此方法为每隔固定时间会发起一次定位请求,为了减少电量消耗或网络流量消耗,
// 注意设置合适的定位时间的间隔(最小间隔支持为2000ms),并且在合适时间调用stopLocation()方法来取消定位请求
// 在定位结束后,在合适的生命周期调用onDestroy()方法
// 在单次定位情况下,定位无论成功与否,都无需调用stopLocation()方法移除请求,定位sdk内部会移除
// 设置是否只定位一次,默认为false
mLocationOption.setOnceLocation(true);
//设置是否强制刷新WIFI,默认为强制刷新
mLocationOption.setWifiActiveScan(false);
mlocationClient.startLocation();
}
}
@Override
public void deactivate() {
mListener = null;
if (mlocationClient != null) {
mlocationClient.stopLocation();
mlocationClient.onDestroy();
}
mlocationClient = null;
}
@Override
public View getInfoWindow(Marker marker) {
tv = new TextView(this);
tv.setBackgroundResource(R.drawable.bg_myinfowindow2_0);
tv.setPadding(4, 0, 4, 16);
tv.setGravity(Gravity.CENTER);
if (mMarker != null) {
tv.setText(zhan_name);
et_address.setText(zhan_address);
}
tv.setTextColor(getResources().getColor(R.color.hintColor));
tv.setTextSize(15);
return tv;
}
@Override
public View getInfoContents(Marker marker) {
return null;
}
@Override
public void onLocationChanged(AMapLocation amapLocation) {
if (amapLocation != null
&& amapLocation.getErrorCode() == 0) {
try {
Log.e("---------------", "--------------");
mlocationClient.stopLocation();
poi_jing = String.valueOf(amapLocation.getLongitude());
poi_wei = String.valueOf(amapLocation.getLatitude());
} catch (NullPointerException e) {
e.printStackTrace();
}
if (!isFirstLoc) {
center = new LatLng(amapLocation.getLatitude(), amapLocation.getLongitude());
//设置缩放级别
aMap.moveCamera(CameraUpdateFactory.zoomTo(16));
//将地图移动到定位点
aMap.moveCamera(CameraUpdateFactory.changeLatLng(center));
//点击定位按钮 能够将地图的中心移动到定位点
mListener.onLocationChanged(amapLocation);
}
isFirstLoc = false;
} else {
String errText = "定位失败," + amapLocation.getErrorCode() + ": " + amapLocation.getErrorInfo();
Log.e("AmapErr", errText);
Toast.makeText(this, errText, Toast.LENGTH_SHORT).show();
}
}
}
|