注意:我使用过谷歌地图V2,所以请发布与之相关的内容.
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;@OverrIDeprotected 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); } });}@OverrIDepublic 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;}@OverrIDeprotected 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;}@OverrIDepublic 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.@R_404_1715@(); } }}@OverrIDepublic voID onCameraChange(Cameraposition arg0) { // Todo auto-generated method stub} }解决方法 您可以使用:-
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)); }总结
以上是内存溢出为你收集整理的当我在Android中的Google maps v2中滚动地图时,如何获取中心点?全部内容,希望文章能够帮你解决当我在Android中的Google maps v2中滚动地图时,如何获取中心点?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)