您好我最初能够获得一些关于此类设置的指导,但是发生了错误。当我尝试将LatLng放入每个对象的创建时,它在逗号下显示为红色。谁能告诉我为什么?我是否错过了一个括号或什么,或者在将LatLng输入到对象的创建中时如何格式化LatLng?
public class Cinema {
private GoogleMap googleMap;
private HashMap cinemaMarker;
String name;
String webSite;
LatLng position;
public Cinema(String name, String webSite, LatLng position){
this.name = name;
this.webSite = webSite;
this.position = position;
}
public String getName(){
return name;
}
public String getWebSite(){
return webSite;
}
public LatLng getPosition(){
return position;
}
public MarkerOptions getMarker(){
return new MarkerOptions().position(position).title(name);
}
List<Cinema> cinemas = new ArrayList<>();
public void MockData(){
cinemas.add(new Cinema("ODEON","www.odeon.co.uk/films/", (54.598693,-5.925955));
cinemas.add(new Cinema("Movie House -Dublin Rd","www.moviehouse.co.uk/Movie/Cinema/1/dublin_road", (54.592211, -5.931512));
cinemas.add(new Cinema("Queen's Film Theatre","queensfilmtheatre.com/Whats-On", (54.585406, -5.933929));
cinemas.add(new Cinema("Strand Cinema","www.cinemas-online.co.uk/films-out-now/", (54.600542, -5.879803 ));
cinemas.add(new Cinema("Odyssey Cinema","www.odysseycinemas.co.uk/en.aspx", (54.603835, -5.916253));
cinemas.add(new Cinema("Omniplex Kennedy Centre","www.omniplex.ie/", (54.580723, -5.979174));
cinemas.add(new Cinema("Movie House - City Side","www.moviehouse.co.uk/Movie/Cinema/2/city_side", (54.608512, -5.926765));
}
答案 0 :(得分:2)
更改MockData中的所有行,以便调用LatLng contructor:
cinemas.add(new Cinema("ODEON","www.odeon.co.uk/films/", new LatLng(54.598693,-5.925955))
公共构造函数摘要
LatLng(double latitude, double longitude)
答案 1 :(得分:1)
在Java中使用构造函数:)
cinemas.add(new Cinema("ODEON","www.odeon.co.uk/films/", new LatLng(54.598693,-5.925955));
答案 2 :(得分:0)
您的方法Cinema
的参数列表是 -
因此,当您实例化时,必须将这些内容传递给方法。你过世了
cinemas.add(new Cinema("ODEON","www.odeon.co.uk/films/", (54.598693,-5.925955));
"ODEON"
是字符串(正确)"www.odeon.co.uk/films/"
是字符串(正确)(54.598693,-5.925955)
不是latlng(不正确)所以你必须在第三个参数中传递一个latlng并执行此传递
new LatLng(54.598693,-5.925955)
。
希望这个答案能让你明白自己的错误。