我想知道如何在android中为我的地图添加自定义标记。自定义标记位于我的drawable文件夹中,名为car.png。下面给出了android.At present中的谷歌地图API v2的代码
我正在获取标准的谷歌地图标记
import com.google.android.gms.maps.CameraUpdate;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
public class Map extends FragmentActivity {
private GoogleMap mMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mapp);
Intent intent = getIntent();
Bundle extras = intent.getExtras();
String lats = extras.getString("LATITUDE");
String longts = extras.getString("LONGITUDE");
String speeds = extras.getString("SPEED");
double latt= Double.parseDouble(lats);
double longt=Double.parseDouble(longts);
final LatLng Location=new LatLng(latt,longt);
mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map1))
.getMap();
mMap.addMarker(new MarkerOptions().position(Location).title("The Speed Of The Vehicle Is: " + speeds + "kmph"));
mMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
CameraUpdate cam=CameraUpdateFactory.newLatLngZoom(Location,15);
mMap.animateCamera(cam);
}
}
答案 0 :(得分:3)
此页面包含有关如何将自定义图像用作标记的信息:https://developers.google.com/maps/documentation/android/marker#customize_a_marker
以上来源的例子:
private static final LatLng MELBOURNE = new LatLng(-37.813, 144.962);
private Marker melbourne = mMap.addMarker(new MarkerOptions()
.position(MELBOURNE)
.title("Melbourne")
.snippet("Population: 4,137,400")
.icon(BitmapDescriptorFactory.fromResource(R.drawable.arrow)));
您可以将fromResource
,fromFile
,fromBitmap
和fromAsset
与BitmapDescriptorFactory
班级一起使用:https://developer.android.com/reference/com/google/android/gms/maps/model/BitmapDescriptorFactory.html