[英]add dynamic marker to maps
Im trying to create a dynamic marker in google maps but the map doesen't load, the maps activity does load but it doesen't create de marker. 我正在尝试在Google地图中创建动态标记,但地图未加载,地图活动已加载,但未创建de标记。 here is the code:
这是代码:
import android.support.v4.content.ContextCompat;
import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
import android.widget.Toast;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.CameraPosition;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
import android.content.pm.PackageManager;
public class Mapa extends FragmentActivity implements OnMapReadyCallback {
private GoogleMap mMap;
public double posx;
public double posy;
public String desc;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_mapa);
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
//SupportMapFragment googleMap=(SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map);
Bundle b = getIntent().getExtras();
posx= b.getDouble("PosicionX");
posy= b.getDouble("PosicionY");
desc = b.getString("Descripcion");
}
/**
* Manipulates the map once available.
* This callback is triggered when the map is ready to be used.
* This is where we can add markers or lines, add listeners or move the camera. In this case,
* we just add a marker near Sydney, Australia.
* If Google Play services is not installed on the device, the user will be prompted to install
* it inside the SupportMapFragment. This method will only be triggered once the user has
* installed Google Play services and returned to the app.
*/
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
// Add a marker in Sydney and move the camera
LatLng lugar = new LatLng(posx, posy);
mMap.addMarker(new MarkerOptions().position(lugar).title(desc));
mMap.moveCamera(CameraUpdateFactory.newLatLng(lugar));
}
}
Im using a bundle to receive the information send from the previous activty, which sends two doubles and one string. 我使用捆绑包接收从先前活动发送的信息,该活动发送两个双打和一个字符串。 for some reason it opens the maps_activity when i run it on my phone but it doesen't create the marker.
由于某种原因,当我在手机上运行它时,它会打开maps_activity,但它不会创建标记。 I wont paste the whole xml code, but the map object is named "map"
我不会粘贴整个xml代码,但是地图对象名为“地图”
事实证明,代码很好,问题出在我正在开发的Android版本上,因为它是我手机上的Android版本的较旧版本,由于某种原因,它无法正确打开google maps,因此我不得不将Hole应用程序重新制作为手机上的Android版本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.