在android中滚动Google maps v2时获取地图中心点?
大家好,我正在做一个应用程序,我的应用程序中有一个地图页面,所以我实现了谷歌地图V2,我有一个问题,当我滚动地图时,我想得到地图的中心点,如果我滚动地图,我离开它,它就会得到地图的中心点,所以任何人都可以建议解决这个问题,这可能会有帮助,谢谢预付款 注意:我使用了谷歌地图V2,请发布相关信息在android中滚动Google maps v2时获取地图中心点?,android,google-maps,maps,android-mapview,Android,Google Maps,Maps,Android Mapview,大家好,我正在做一个应用程序,我的应用程序中有一个地图页面,所以我实现了谷歌地图V2,我有一个问题,当我滚动地图时,我想得到地图的中心点,如果我滚动地图,我离开它,它就会得到地图的中心点,所以任何人都可以建议解决这个问题,这可能会有帮助,谢谢预付款 注意:我使用了谷歌地图V2,请发布相关信息 public class Mapview extends FragmentActivity implements OnMapClickListener, OnCameraChangeListener{ f
public class Mapview extends FragmentActivity implements OnMapClickListener, OnCameraChangeListener{
final int RQS_GooglePlayServices = 1;
private GoogleMap myMap;
Location myLocation;
TextView tvLocInfo;
GPSTracker gps;
public double Latitude,Longitude;
String Datetime, addr,RegUID;
public String lat,longd;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mapview);
tvLocInfo = (TextView)findViewById(R.id.locinfo);
FragmentManager myFragmentManager = getSupportFragmentManager();
SupportMapFragment mySupportMapFragment = (SupportMapFragment)myFragmentManager.findFragmentById(R.id.map);
myMap = mySupportMapFragment.getMap();
myMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
myMap.setMyLocationEnabled(true);
myMap.setOnMapClickListener(this);
Projection P = myMap.getProjection();
Log.e("lat", String.valueOf(Latitude));
Log.e("lat", String.valueOf(Longitude));
Button mDone = (Button) findViewById(R.id.button1);
mDone.setOnClickListener(new View.OnClickListener() {
@SuppressLint("SimpleDateFormat")
public void onClick(View v) {
//Toast.makeText(getBaseContext(), "latitude"+lat+""+"longitude"+longd , Toast.LENGTH_LONG).show();
String timeStamp = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Calendar.getInstance().getTime());
Datetime = timeStamp.toString();
Log.e("t", Datetime);
RegUID = Utils.RegisterUserId;
Log.e("t", RegUID);
final ProgressDialog dialog = ProgressDialog.show(Mapview.this, "", Utils.Loading, true);
dialog.show();
Handler handler = new Handler();
handler.postDelayed(new Runnable(){
@SuppressWarnings("unused")
public void run()
{
try
{
String EMPLOYEE_SERVICE_URI = Utils.Request+"UserID="+RegUID+"&Location="+URLEncoder.encode(addr,"UTF-8")+"&Latitude="+lat+"&Longitude="+longd+"&RequestDate="+URLEncoder.encode(Datetime,"UTF-8");
Log.e(EMPLOYEE_SERVICE_URI, EMPLOYEE_SERVICE_URI);
JSONObject JObject = Utils.getResult(EMPLOYEE_SERVICE_URI);
//Toast.makeText(Mapview.this,JObject.toString(), Toast.LENGTH_LONG).show();
if(JObject!=null)
{
if(JObject.getBoolean("Valid"))
{
AlertDialog alertDialog = new AlertDialog.Builder(Mapview.this).create();
Utils.callAlert(JObject.getString("Message"), alertDialog);
}
else
{
AlertDialog alertDialog = new AlertDialog.Builder(Mapview.this).create();
Utils.callAlert(JObject.getString("Message"), alertDialog);
}
}
else
{
AlertDialog alertDialog = new AlertDialog.Builder(Mapview.this).create();
Utils.callAlert(JObject.getString("Message"), alertDialog);
}
}
catch (Exception e)
{
//Toast.makeText(Mapview.this,e.toString(), Toast.LENGTH_LONG).show();
Log.e("Exception", e.toString());
}
dialog.dismiss();
}//run() ends
}, 5000);
}
});
}
@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 true;
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());
if (resultCode == ConnectionResult.SUCCESS){
Toast.makeText(getApplicationContext(),
"isGooglePlayServicesAvailable SUCCESS",
Toast.LENGTH_LONG).show();
}else{
GooglePlayServicesUtil.getErrorDialog(resultCode, this, RQS_GooglePlayServices);
}
}
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
Log.i("test","onScroll");
return false;
}
@Override
public void onMapClick(LatLng point) {
Log.e("lat", String.valueOf(point.latitude));
Log.e("lat", String.valueOf(point.longitude));
Latitude =point.latitude;
Longitude = point.longitude;
lat = String.valueOf(point.latitude);
longd = String.valueOf(point.longitude);
myMap.moveCamera(CameraUpdateFactory.newLatLng(point));
gps = new GPSTracker(Mapview.this);
// check if GPS enabled
if(gps.canGetLocation())
{
Geocoder geoCoder = new Geocoder(getBaseContext(), Locale.getDefault());
try {
List<Address> addresses = geoCoder.getFromLocation(Latitude, Longitude, 1);
if(addresses != null) {
Address returnedAddress = addresses.get(0);
StringBuilder strReturnedAddress = new StringBuilder("");
for(int i=0; i<returnedAddress.getMaxAddressLineIndex(); i++) {
strReturnedAddress.append(returnedAddress.getAddressLine(i)).append("\n");
}
addr = new String(strReturnedAddress);
tvLocInfo.setText(addr.toString());
//Toast.makeText(getApplicationContext(), addr.toString(),Toast.LENGTH_LONG).show();
}
else
{
Toast.makeText(getApplicationContext(), "Gps location address is unavailable please try again later",
Toast.LENGTH_LONG).show();
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
@Override
public void onCameraChange(CameraPosition arg0) {
// TODO Auto-generated method stub
}
}
公共类Mapview扩展了FragmentActivity实现OnMapClickListener、OnCameraChangeListener{
最终int RQS_GooglePlayServices=1;
私人谷歌地图;
位置;
TextView-tvLocInfo;
全球定位系统;
公共双纬度、经度;
字符串Datetime,addr,RegUID;
公共字符串lat,long;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.mapview);
tvLocInfo=(TextView)findViewById(R.id.locinfo);
FragmentManager myFragmentManager=getSupportFragmentManager();
SupportMapFragment mySupportMapFragment=(SupportMapFragment)myFragmentManager.findFragmentById(R.id.map);
myMap=mySupportMapFragment.getMap();
myMap.setMapType(GoogleMap.MAP\u TYPE\u NORMAL);
myMap.setMyLocationEnabled(true);
myMap.setOnMapClickListener(这个);
Projection P=myMap.getProjection();
Log.e(“lat”,String.valueOf(纬度));
Log.e(“lat”,String.valueOf(经度));
按钮mDone=(按钮)findViewById(R.id.button1);
setOnClickListener(新视图.OnClickListener(){
@SuppressLint(“SimpleDataFormat”)
公共void onClick(视图v){
//Toast.makeText(getBaseContext(),“纬度”+lat+“+”经度“+longd,Toast.LENGTH_LONG).show();
字符串时间戳=新的SimpleDataFormat(“yyyy-MM-dd HH:MM:ss”).format(Calendar.getInstance().getTime());
Datetime=timeStamp.toString();
Log.e(“t”,日期时间);
RegUID=Utils.RegisterUserId;
Log.e(“t”,RegUID);
最终ProgressDialog=ProgressDialog.show(Mapview.this,“,Utils.Loading,true);
dialog.show();
Handler=newhandler();
handler.postDelayed(新的Runnable(){
@抑制警告(“未使用”)
公开募捐
{
尝试
{
字符串EMPLOYEE_SERVICE_URI=Utils.Request+“UserID=“+RegUID+”&Location=“+urlcoder.encode(addr,“UTF-8”)+”&纬度=“+lat+”&经度=“+longd+”&RequestDate=“+urlcoder.encode(Datetime,“UTF-8”);
Log.e(雇员服务URI,雇员服务URI);
JSONObject JObject=Utils.getResult(员工\服务\ URI);
//Toast.makeText(Mapview.this,JObject.toString(),Toast.LENGTH_LONG.show();
if(JObject!=null)
{
if(JObject.getBoolean(“有效”))
{
AlertDialog AlertDialog=新建AlertDialog.Builder(Mapview.this.create();
Utils.callAlert(JObject.getString(“消息”),alertDialog);
}
其他的
{
AlertDialog AlertDialog=新建AlertDialog.Builder(Mapview.this.create();
Utils.callAlert(JObject.getString(“消息”),alertDialog);
}
}
其他的
{
AlertDialog AlertDialog=新建AlertDialog.Builder(Mapview.this.create();
Utils.callAlert(JObject.getString(“消息”),alertDialog);
}
}
捕获(例外e)
{
//Toast.makeText(Mapview.this,例如toString(),Toast.LENGTH_LONG).show();
Log.e(“异常”,例如toString());
}
dialog.dismise();
}//run()结束
}, 5000);
}
});
}
@凌驾
公共布尔onCreateOptions菜单(菜单){
//为菜单充气;这会将项目添加到操作栏(如果存在)。
getMenuInflater().充气(R.menu.main,menu);
返回true;
}
@凌驾
受保护的void onResume(){
//TODO自动生成的方法存根
super.onResume();
int-resultCode=GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());
if(resultCode==ConnectionResult.SUCCESS){
Toast.makeText(getApplicationContext(),
“谷歌PlayServicesAvailable SUCCESS”,
Toast.LENGTH_LONG).show();
}否则{
GooglePlayServicesUtil.getErrorDialog(结果代码,this,RQS_GooglePlayServices);
}
}
公共布尔onScroll(MotionEvent e1、MotionEvent e2、浮点距离X、浮点距离Y){
Log.i(“测试”、“onScroll”);
返回false;
}
@凌驾
公共空区(停车点){
Log.e(“lat”,String.valueOf(point.latitude));
Log.e(“lat”,String.valueOf(point.longitude));
纬度=点。纬度;
经度=点。经度;
lat=字符串.valueOf(点纬度);
longd=字符串.valueOf(点.经度);
myMap.moveCamera(CameraUpdateFactory.newLatLng(点));
gps=新的GP斯特拉克(Mapview.this);
//检查是否启用了GPS
if(gps.canGetLocation())
{
Geocoder Geocoder=新的地理编码器(getBaseContext(),Locale.getDefault());
试一试{
列表地址=geoCoder.getFromLocation(纬度,经度,1);
如果(地址!=null){
返回的地址地址=地址。获取(0);
StringBuilder strReturnedAddress=新StringBuilder(
myMap.setOnCameraChangedListener(this);
onCameraChange(CameraPosition position) {
LatLng target = position.target;
// do what you need with the position here
}
private void setDefaultMapPosition(LatLng latLng) {
CameraPosition camPos =
new CameraPosition.Builder().target(latLng)
.zoom(A_DEFAULT_MAP_ZOOM)
.bearing(0)
.tilt(0)
.build();
myMap.moveCamera(
CameraUpdateFactory.newCameraPosition(camPos));
}