本文介绍了.snippet中的多行或换行符(谷歌地图apiv2)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在开发谷歌地图APIv2。我现在面临的问题是我只能在信息窗口/代码段中添加一行字。但是我想要的输出能够以折线形式显示如下所示。那么是否有任何可能的方法来解决它?
示例:
坐标:03.05085,101.70506
速度限制:80 km / h
$ b public class MainActivity extends FragmentActivity {
static final LatLng SgBesi = new LatLng(03.05085,101.76022);
static final LatLng JB = new LatLng(1.48322,103.69065);
私人GoogleMap地图;
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
$ b map =((SupportMapFragment)getSupportFragmentManager()。findFragmentById(R.id.map))
.getMap();
$ b $ map.addMarker(new MarkerOptions()。position(SgBesi)
.title(KM D7.7 Sungai Besi)//名称
.snippet(坐标: 03.05085,101.70506)); //描述
map.addMarker(new MarkerOptions()。position(JB)
.title(test)
.snippet(嘿,你好吗? ));
// .icon(BitmapDescriptorFactory // set icon
// .fromResource(R.drawable.ic_launcher)));
//以15倍的放大比例立即移动相机。
map.moveCamera(CameraUpdateFactory.newLatLngZoom(SgBesi,15));
//放大,动画摄像机。
map.animateCamera(CameraUpdateFactory.zoomTo(15),2000,null);
$ div $解析方案
你需要使用来更改<$ c $的布局c> InfoWindow 添加到使用布局文件定义的自定义设计中。基本上你需要:
$ b
- 使用
声明你的函数> GoogleMap.setInfoWindowAdapter(Yourcustominfowindowadpater)
- 有如下类:
...
class Yourcustominfowindowadpater implements InfoWindowAdapter {
private final查看mymarkerview;
Yourcustominfowindowadpater(){
mymarkerview = getLayoutInflater()
.inflate(R.layout.custominfowindow,null);
}
public查看getInfoWindow(标记标记){
render(marker,mymarkerview);
返回mymarkerview;
}
public View getInfoContents(Marker marker){
return null;
}
private void render(Marker marker,View view){
//添加代码以设置所需值
//对于custominfowindow中的每个元素布局文件
}
}
I'm developing in google maps APIv2. The issue that I'm facing now is I only able to add in one line of word in info windows/snippet. But the output that I want is able to display in break line form as example show below. So is there any possible methods to solve it?
Example:
Coordinate: 03.05085, 101.70506
Speed Limit: 80 km/h
public class MainActivity extends FragmentActivity {
static final LatLng SgBesi = new LatLng(03.05085, 101.76022);
static final LatLng JB = new LatLng(1.48322, 103.69065);
private GoogleMap map;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))
.getMap();
map.addMarker(new MarkerOptions().position(SgBesi)
.title("KM D7.7 Sungai Besi") //name
.snippet("Coordinate: 03.05085, 101.70506")); //description
map.addMarker(new MarkerOptions().position(JB)
.title("test")
.snippet("Hey, how are you?"));
// .icon(BitmapDescriptorFactory //set icon
// .fromResource(R.drawable.ic_launcher)));
// move the camera instantly with a zoom of 15.
map.moveCamera(CameraUpdateFactory.newLatLngZoom(SgBesi, 15));
// zoom in, animating the camera.
map.animateCamera(CameraUpdateFactory.zoomTo(15), 2000, null);
}
}
解决方案
You need to use a custom InfoWindowAdapter to change the layout of InfoWindow
to a custom design defined using a layout file. Basically you need to :
- Declare your function using
GoogleMap.setInfoWindowAdapter(Yourcustominfowindowadpater)
- Have a class like below:
...
class Yourcustominfowindowadpater implements InfoWindowAdapter {
private final View mymarkerview;
Yourcustominfowindowadpater() {
mymarkerview = getLayoutInflater()
.inflate(R.layout.custominfowindow, null);
}
public View getInfoWindow(Marker marker) {
render(marker, mymarkerview);
return mymarkerview;
}
public View getInfoContents(Marker marker) {
return null;
}
private void render(Marker marker, View view) {
// Add the code to set the required values
// for each element in your custominfowindow layout file
}
}
这篇关于.snippet中的多行或换行符(谷歌地图apiv2)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!