我如何可以创建一个包含经纬度和使用循环标记在谷歌地图Android版中的位置的数组 [英] How can I create an array that contains latitude and longitude and use for loop to mark the positions on google map in android
问题描述
我刚刚开始在Android和之后很长一段时间我得到了我的谷歌地图的工作,并已能够把标记上的编码。
I've just started coding in android and after a very long time I got my google map to work and have been able to put markers on it.
我想下一步要做的就是创建的经纬度信息的数组,并使用循环来把标记的谷歌地图。我想不出该怎么办。可能有人请帮助我。我这样做远远以下。
What I want to do next is create a array of latlng and use for loop to put a marker on the google maps. I cannot figure out how to do. Could someone please help me. I have done the following so far.
ArrayList<Markers> mMap = new ArrayList<Markers>();
public ArrayList arraylist[] = {new ArrayList(
new LatLng(30.243442, -1.432320)),
我想扩大这个以后,所以我想用数组列表。
I would like to expand this later, hence I would like to use array list.
我知道如何在for循环工作,但我不能工作了如何使用这个工具它,因为我不能从阵列这些位置在我的地图标记。
I understand how the for loop works, but I cannot work out how to implement it with this as I cannot get those locations from array to tag on my map.
for (i = 0; i < cars.length; i++) {
mMap.addMarker(new MarkerOptions()
.position(new LatLng(10, 10))
.title("Hello world"));
}
我彻底从这个阶段丢失。可能有人请引导和帮助我。
I am completely lost from this stage. Could someone please guide and help me out.
感谢。
推荐答案
首先,你想要存储的经纬度对象的数组。因此,声明一个像这样:
Firstly, you are wanting an array that stores the LatLng object. So, declare one like so:
ArrayList<LatLng> locations;
而且你还需要初始化你的ArrayList
And you also need to initialise your ArrayList:
locations = new ArrayList();
现在你可以添加位置到数组,使用ArrayList.add方式:
Now you can add locations to the array, using the ArrayList.add method:
locations.add(new LatLng(latitude, longitude));
现在,你填写一些经纬度的一个ArrayList,您可以使用foreach循环在他们重复,像这样:
Now that you have an ArrayList filled with some LatLng's, you can iterate over them using a foreach loop, like so:
for(LatLng location : locations){
mMap.addMarker(new MarkerOptions()
.position(location)
.title(...)
}
以上基本内容:
有关在位置ArrayList中的每个位置,添加一个新的标记,标记所在的位置就是我们从出阵列
For each location in the locations ArrayList, add a new marker, where the position of the marker is the location we're retrieving from out array
绑到一起:
ArrayList<LatLng> locations = new ArrayList();
locations.add(new LatLng(30.243442, -1.432320));
locations.add(new LatLng(... , ...));
.
.
.
for(LatLng location : locations){
mMap.addMarker(new MarkerOptions()
.position(location)
.title(...)
}
这篇关于我如何可以创建一个包含经纬度和使用循环标记在谷歌地图Android版中的位置的数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!