Can someone give me an example of how to get the center coordinates of the current displayed screen? I would like my objects to always be relative to the center coordinates of the active view.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
You can try with DisplayMetrics
to achieve your solution
int mWidth= this.getResources().getDisplayMetrics().widthPixels;
int mHeight= this.getResources().getDisplayMetrics().heightPixels;
回答2:
Here is how I resolved the issue. As a background, I have a button that once the user moves the map to the desired location (cross hairs showing the centre of map) they can tap the button and a marker appears in the centre of the map.
findViewById(R.id.addMarker).setOnClickListener(
new View.OnClickListener(){
@Override
public void onClick(View view) {
if(myMap != null){
double myLat = myMap.getCameraPosition().target.latitude;
double myLng = myMap.getCameraPosition().target.longitude;
LatLng markerPoint = new LatLng(myLat, myLng);
myMap.addMarker(new MarkerOptions().position(markerPoint)).setTitle("new marker");
}
}
}
);
回答3:
int cx =screenHeight = displaymetrics.heightPixels;
int cy = screenWidth = displaymetrics.widthPixels;
float finalRadius = (float) Math.sqrt(cx * cx + cy * cy);
float is the center if the object