我目前正在创建一个使用Google Maps API的应用。这就是我想要做的事情:
我有活动A.活动A中有一个按钮。当点击按钮时,我想在特定的坐标和缩放级别打开MapsActivtiy(没有谷歌地图应用程序)。我在互联网上搜索了很多,但我找不到答案。
请注意,我还有活动B,活动C,活动D等,每个都包含一个按钮。每个活动中的每个按钮都应该在不同的坐标和缩放上打开MapsActivity。
解决方案(我不能回答并接受它,因为问题已经结束)
在活动中A:
//onClick method
public void viewOnMap(View view)
{
LatLng coords = new LatLng(50.191067, 18.452964);
Bundle bundle = new Bundle();
bundle.putParcelable("coords", coords);
Intent intent = new Intent(this, MapsActivity.class);
intent.putExtras(bundle);
startActivity(intent);
}
在地图中激活onMapReady()
Intent intent = getIntent();
LatLng coords = intent.getParcelableExtra("coords");
//some maps code etc...
if(coords != null)
{
if (coords.equals(some_coords_1))
{
LatLng coords_zoom = new LatLng(coords.latitude, coords.longitude);
googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(coords.latitude, coords.longitude), 17));
googleMap.moveCamera(CameraUpdateFactory.newLatLng(coords_zoom));
}
if(coords.equals(some_coords_2)
{
LatLng coords_zoom = new LatLng(coords.latitude, coords.longitude);
googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(coords.latitude, coords.longitude), 17));
googleMap.moveCamera(CameraUpdateFactory.newLatLng(coords_zoom))
}
答案 0 :(得分:2)
内部活动A:
将Intent中的坐标传递给另一个活动。
Intent intent = getIntent();
if(intent.hasExtra("LatLng")){
mLatLng = intent.getParcelableExtra("LatLng");
}
public void onMapReady(){
mGoogleMap.animateCamera(CameraUpdateFactory.newLatLng(mLatLng));
}
内部活动B:
检查您是否正确收到了额外内容。然后,在启动地图后,移动相机。
import tensorflow as tf
def matrix_with_upper_values(upper_values):
# Check that the input is at least a vector
upper_values = tf.convert_to_tensor(upper_values)
upper_values.get_shape().with_rank_at_least(1)
# Put the batch dimensions last
upper_values = tf.transpose(
upper_values,
tf.concat(0, [[tf.rank(upper_values) - 1],
tf.range(tf.rank(upper_values) - 1)]))
input_shape = tf.shape(upper_values)[0]
# Compute the size of the matrix that would have this upper triangle
matrix_size = (1 + tf.cast(tf.sqrt(tf.cast(input_shape * 8 + 1, tf.float32)),
tf.int32)) // 2
# Check that the upper triangle size is valid
check_size_op = tf.Assert(
tf.equal(matrix_size ** 2, input_shape * 2 + matrix_size),
["Not a valid upper triangle size: ", input_shape])
with tf.control_dependencies([check_size_op]):
matrix_size = tf.identity(matrix_size)
# Compute indices for the whole matrix and the upper diagonal
index_matrix = tf.reshape(tf.range(matrix_size ** 2),
[matrix_size, matrix_size])
diagonal_indicies = (matrix_size * tf.range(matrix_size)
+ tf.range(matrix_size))
upper_triangular_indices, _ = tf.unique(tf.reshape(
tf.matrix_band_part(
index_matrix, 0, -1) # upper triangular part
- tf.diag(diagonal_indicies), # remove diagonal
[-1]))
batch_dimensions = tf.shape(upper_values)[1:]
return_shape_transposed = tf.concat(0, [[matrix_size, matrix_size],
batch_dimensions])
# Fill everything else with zeros; later entries get priority
# in dynamic_stitch
result_transposed = tf.reshape(
tf.dynamic_stitch(
[index_matrix,
upper_triangular_indices[1:]], # discard 0
[tf.zeros(return_shape_transposed, dtype=upper_values.dtype),
upper_values]),
return_shape_transposed)
# Transpose the batch dimensions to be first again
return tf.transpose(
result_transposed,
tf.concat(0, [tf.range(2, tf.rank(upper_values) + 1), [0, 1]]))
with tf.Session():
print(matrix_with_upper_values([1]).eval())
print(matrix_with_upper_values([2,7,1]).eval())
print(matrix_with_upper_values([3,1,4,1,5,9]).eval())
print(matrix_with_upper_values([]).eval())
print(matrix_with_upper_values([[2,7,1],[4,3,5]]).eval())
print(matrix_with_upper_values(tf.zeros([0, 3])).eval())
我希望它有所帮助!