【发布时间】:2015-05-31 21:55:36
【问题描述】:
问题是我无法单击标记的自定义信息窗口内的 andoid 地图 v2 上显示的 URL“www.news.com”。 在 xml 布局文件中,我有:
<TextView
android:id="@+id/web"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autoLink="web"
android:background="#ADD8E6"
android:text="www.google.gr"
android:linksClickable="true"/>
在 Java 活动文件中我有:
mMap.setInfoWindowAdapter(new InfoWindowAdapter() {
// Use default InfoWindow frame
@Override
public View getInfoWindow(Marker marker) {
return null;
}
// Defines the contents of the InfoWindow
@Override
public View getInfoContents(Marker marker) {
// Getting view from the layout file info_window_layout
View v = getLayoutInflater().inflate(R.layout.infowindow_layout, null);
TextView tvTitle = (TextView) v.findViewById(R.id.title);
tvTitle.setText(marker.getTitle());
TextView tvSnippet = (TextView) v.findViewById(R.id.snippet);
tvSnippet.setText(marker.getSnippet());
// URL
final TextView tvURL =(TextView) v.findViewById(R.id.web);
tvURL.setText("www.news.com");
Linkify.addLinks(tvURL, Linkify.WEB_URLS);
// URL
链接以蓝色和下划线正确显示,但我发现它只是一个死链接。如果我们尝试点击它,什么都不会发生。我必须做什么才能使链接处于活动状态?
在 java 文件中插入新代码:
mMap.setInfoWindowAdapter(new InfoWindowAdapter() {
// Use default InfoWindow frame
@Override
public View getInfoWindow(Marker marker) {
return null;
}
// Defines the contents of the InfoWindow
@Override
public View getInfoContents(Marker marker) {
// Getting view from the layout file info_window_layout
View v = getLayoutInflater().inflate(R.layout.infowindow_layout, null);
TextView tvTitle = (TextView) v.findViewById(R.id.title);
tvTitle.setText(marker.getTitle());
TextView tvSnippet = (TextView) v.findViewById(R.id.snippet);
tvSnippet.setText(marker.getSnippet());
// URL
final TextView tvWeb =(TextView) v.findViewById(R.id.web);
tvWeb.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent viewIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.news.com"));
startActivity(viewIntent);
}
});
XML 使用相同:
<TextView
android:id="@+id/web"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autoLink="web"
android:background="#ADD8E6"
android:text="www.news.com"
android:linksClickable="true"/>
问题仍然存在..URL 链接无效,我无法打开浏览器。
当我点击自定义信息窗口时,现在 URL 链接正在打开到移动浏览器。
mMap.addMarker(new MarkerOptions().position(new LatLng(39.686286, 19.838443)).title("Hi").snippet("Name, Surname, phone: 1093595, website: www.news.com").icon(BitmapDescriptorFactory.fromResource(R.drawable.location_icon)));
mMap.setOnInfoWindowClickListener(new OnInfoWindowClickListener() {
@Override
public void onInfoWindowClick(Marker marker) {
Intent viewIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.news.com"));
startActivity(viewIntent);
}
});
但我有大约 300 个标记,我希望为每个标记打开一个单独的 URL 链接。我该如何实施?
更新代码:
mMap.addMarker(new MarkerOptions().position(new LatLng(36.84449, 22.99999)).title("KALOGRIA").snippet("Name: Messinia \nSurname: Stoupa \nphone: +99999999 \nwebsite: http://www.news.com/").icon(BitmapDescriptorFactory.fromResource(R.drawable.location_icon)));
mMap.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener()
{
@Override
public void onInfoWindowClick(Marker marker)
{
//String webUrl = marker.getSnippet();
String snippetStr = marker.getSnippet();
String webUrl = snippetStr.substring(snippetStr.lastIndexOf("website:") + 1);
Intent viewIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(webUrl));
startActivity(viewIntent);
}
});
【问题讨论】:
-
Hack 用于强制信息窗口查看活动/交互性:gist.github.com/corsair992/8313269
标签: android google-maps-markers google-maps-api-2