1

我无法在目标 C 的谷歌地图上显示两个标记。我正在尝试将两个值传递给它。我意识到它可能只是被覆盖了,但我还不能修复它。请帮忙。这是我的 .m 文件中的代码:

GMSMarker *marker = [[GMSMarker alloc] init];

marker.position=CLLocationCoordinate2DMake(toLatitudeDouble, toLongitudeDouble);
marker.title=toLocationFromResultVC;
marker.snippet=@"Destination";



marker.position=CLLocationCoordinate2DMake(fromLatitudeDouble, fromLongitudeDouble);
marker.title=fromLocationFromResultVC;
marker.snippet=@"Source";

marker.map = mapView_;

我需要提供更多详细信息吗?我很高兴能得到任何帮助。非常感谢!

4

1 回答 1

9

是的,您正在覆盖价值。您应该创建另一个标记。

GMSMarker *marker = [[GMSMarker alloc] init];

marker.position=CLLocationCoordinate2DMake(toLatitudeDouble, toLongitudeDouble);
marker.title=toLocationFromResultVC; marker.snippet=@"Destination";

// Your're overriding the value here!!
// use GMSMarker *marker2 = [[GMSMarker alloc] init]; and reference it instead in the code below.

marker.position=CLLocationCoordinate2DMake(fromLatitudeDouble, fromLongitudeDouble); 
marker.title=fromLocationFromResultVC; marker.snippet=@"Source";

marker.map = mapView_;

所以,正确的代码是

GMSMarker *marker = [[GMSMarker alloc] init];

marker.position=CLLocationCoordinate2DMake(toLatitudeDouble, toLongitudeDouble);
marker.title=toLocationFromResultVC; marker.snippet=@"Destination";
marker.map = mapView_;

GMSMarker *marker2 = [[GMSMarker alloc] init];
marker2.position=CLLocationCoordinate2DMake(fromLatitudeDouble, fromLongitudeDouble); 
marker2.title=fromLocationFromResultVC; marker.snippet=@"Source";
marker2.map = mapView_;
于 2013-06-15T10:09:55.273 回答