如何在android中显示多个静态位置?

时间:2018-04-06 08:55:20

标签: java android google-maps geolocation latitude-longitude

我正在尝试在地图中的用户当前位置的不同位置显示标记。 现在我已经给出了两个静态值

1。)LatLng one = new LatLng(12.9010, 80.2279);

2。)LatLng two = new LatLng(12.9229, 80.1275);
但是它没有在地图中显示标记,我得到的控制台输出有 lat long值0,0。

这是我用于通过使用静态值在地图中获取标记loaction的代码。

private void addmap() {

    LatLng one = new LatLng(12.9010, 80.2279);
    LatLng two = new LatLng(12.9229, 80.1275);

    LatLngBounds.Builder builder = new LatLngBounds.Builder();

    //add them to builder
    builder.include(one);
    builder.include(two);

    LatLngBounds bounds = builder.build();

    //get width and height to current display screen
    int width = getResources().getDisplayMetrics().widthPixels;
    int height = getResources().getDisplayMetrics().heightPixels;

    // 20% padding
    int padding = (int) (width * 0.20);

    //set latlong bounds
    Mmap.setLatLngBoundsForCameraTarget(bounds);

    //move camera to fill the bound to screen
    Mmap.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, width, height, padding));

    //set zoom to level to current so that you won't be able to zoom out viz. 
  move outside bounds
//        Mmap.setMinZoomPreference(mMap.getCameraPosition().zoom);
}

1 个答案:

答案 0 :(得分:0)

您可以将lat long放在列表中并循环设置多个标记

以下是样本

private async void client_MqttMsgPublishReceived(object sender, MqttMsgPublishEventArgs e)
{
    string ReceivedMessage;
    if (e.Topic == Topic1)
    {
        ReceivedMessage = Encoding.UTF8.GetString(e.Message);
        await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
        {
            Sensor1Reading.Text = ReceivedMessage;
        });
    }
    else if (e.Topic == Topic2)
    {
        ReceivedMessage = Encoding.UTF8.GetString(e.Message);
        await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
        {
            Sensor2Reading.Text = ReceivedMessage;
        });
    }
}