android googlemaps Marker ko'rinmaydi

Men ilovada xarita yaratmoqchiman va standart ko'rsatgich bo'ladi Bu erda Google xarita xml faoliyati mavjud Belgini ko'rsatish uchun ko'p vaqtni sinab ko'rdim, lekin uni ko'rmayapman, men bu erda bir nechta mavzularni tekshirdim, lekin hech narsa yordam bermadi.


Bu markerni qo'yishga harakat qiladigan java googlemaps faoliyati:

package com.example.nir.nestleapp;

import android.content.pm.PackageManager;
import android.graphics.Camera;
import android.location.Location;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.location.LocationListener;
import com.google.android.gms.location.LocationRequest;
import com.google.android.gms.location.LocationServices;
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.GoogleMapOptions;
import com.google.android.gms.maps.MapFragment;
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.Marker;
import com.google.android.gms.maps.model.MarkerOptions;

import java.io.IOException;
import java.util.Map;

public class GoogleMapsActivity extends FragmentActivity implements OnMapReadyCallback{
    private GoogleMap mMap;
    private LatLng nessziona=new LatLng(31.926597,34.800077);

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_google_maps);
        SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
                .findFragmentById(R.id.map);
        mapFragment.getMapAsync(this);
    }

    @Override
    public void onMapReady(GoogleMap googleMap) {
        mMap = googleMap;
            mMap.addMarker(new MarkerOptions()
                    .position(nessziona)
                    .title("Hello world"));
        mMap.moveCamera((CameraUpdateFactory.newLatLng(nessziona)));
    }



}
0
qo'shib qo'ydi muallif itzswan, manba
qo'shib qo'ydi muallif itzswan, manba
quyida javobni tekshiring
qo'shib qo'ydi muallif Zaki Pathan, manba

7 javoblar

Mening loyihamda bu bor va u ishlaydi:

@Override
public void onMapReady(GoogleMap googleMap) {

    mMap = googleMap;

    BitmapDescriptor markerCustomIcon = BitmapDescriptorFactory.fromResource(R.drawable.trash_recyclebin_empty_closed);
    BitmapDescriptor markerDefaultIcon = BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_VIOLET);
    List markersList = new ArrayList();
    for (int i = 0; i < pgoList.size(); i++) {
        LatLng pos = new LatLng(pgoList.get(i).location.lat, pgoList.get(i).location.lon);
        MarkerOptions marker = new MarkerOptions()
                .position(pos)
                .title(pgoList.get(i).address.full)
                .icon(markerCustomIcon != null ? markerCustomIcon : markerDefaultIcon);
        mMap.addMarker(marker);
        markersList.add( mMap.addMarker(marker));
    }
    builder = new LatLngBounds.Builder();
    for (Marker m : markersList) {
        builder.include(m.getPosition());
    }
    int padding = 0;
    LatLngBounds bounds = builder.build();
    cu = CameraUpdateFactory.newLatLngBounds(bounds, padding);
    mMap.setOnMapLoadedCallback(new GoogleMap.OnMapLoadedCallback() {
        @Override
        public void onMapLoaded() {
            mMap.animateCamera(cu);
        }
    });

}
0
qo'shib qo'ydi

Mening loyihamda bu bor va u ishlaydi:

@Override
public void onMapReady(GoogleMap googleMap) {

    mMap = googleMap;

    BitmapDescriptor markerCustomIcon = BitmapDescriptorFactory.fromResource(R.drawable.trash_recyclebin_empty_closed);
    BitmapDescriptor markerDefaultIcon = BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_VIOLET);
    List markersList = new ArrayList();
    for (int i = 0; i < pgoList.size(); i++) {
        LatLng pos = new LatLng(pgoList.get(i).location.lat, pgoList.get(i).location.lon);
        MarkerOptions marker = new MarkerOptions()
                .position(pos)
                .title(pgoList.get(i).address.full)
                .icon(markerCustomIcon != null ? markerCustomIcon : markerDefaultIcon);
        mMap.addMarker(marker);
        markersList.add( mMap.addMarker(marker));
    }
    builder = new LatLngBounds.Builder();
    for (Marker m : markersList) {
        builder.include(m.getPosition());
    }
    int padding = 0;
    LatLngBounds bounds = builder.build();
    cu = CameraUpdateFactory.newLatLngBounds(bounds, padding);
    mMap.setOnMapLoadedCallback(new GoogleMap.OnMapLoadedCallback() {
        @Override
        public void onMapLoaded() {
            mMap.animateCamera(cu);
        }
    });

}
0
qo'shib qo'ydi

Markeringiz uchun belgini ishlatishga harakat qiling!

Map.addMarker(new MarkerOptions()
                    .position(nessziona)
                    .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED))
                    .title("Hello world"));

Izoh:

Ushbu yo'nalish

.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED))

belgilari uchun belgini, ko'rsatuv qizil rangli belgini qo'shadi.

ushbu bog'lanish bo'limiga qarang. batafsil ma'lumot

0
qo'shib qo'ydi
     MarkerOptions options = new MarkerOptions();

           //Setting the position of the marker
           //Set your multiple driver latitude and langitude below
            options.position(CURRENT_LOCATION);

//Markers from drawable
options.icon(BitmapDescriptorFactory.fromResource(R.drawable.ambulance));

//For custom marker
options.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED))

            options.title("Driver 1");
            options.snippet("Driver-1");
            mMap.addMarker(options);

Umid qilamanki bu sizga yordam beradi. Agar biron-bir muammo bo'lsa, iltimos so'rang. Sizga yordam berishdan baxtiyor :) :)

0
qo'shib qo'ydi
     MarkerOptions options = new MarkerOptions();

           //Setting the position of the marker
           //Set your multiple driver latitude and langitude below
            options.position(CURRENT_LOCATION);

//Markers from drawable
options.icon(BitmapDescriptorFactory.fromResource(R.drawable.ambulance));

//For custom marker
options.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED))

            options.title("Driver 1");
            options.snippet("Driver-1");
            mMap.addMarker(options);

Umid qilamanki bu sizga yordam beradi. Agar biron-bir muammo bo'lsa, iltimos so'rang. Sizga yordam berishdan baxtiyor :) :)

0
qo'shib qo'ydi

Sizning kodingiz to'g'ri ko'rinadi, shuning uchun avval qaydlarni tekshiring (xarita kaliti ba'zi muammolarni keltirib chiqarishi mumkin) va uni kodingizga ham qo'shing ..

@Override 
public void onMapReady(GoogleMap googleMap) {
LatLng nessziona=new LatLng(31.926597,34.800077);
    mMap = googleMap;
 mMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
        mMap.addMarker(new MarkerOptions()
                .position(nessziona)
                .title("Hello world"));
    mMap.moveCamera((CameraUpdateFactory.newLatLng(nessziona,17f)));
} 

XML:


0
qo'shib qo'ydi

Sizning kodingiz to'g'ri ko'rinadi, shuning uchun avval qaydlarni tekshiring (xarita kaliti ba'zi muammolarni keltirib chiqarishi mumkin) va uni kodingizga ham qo'shing ..

@Override 
public void onMapReady(GoogleMap googleMap) {
LatLng nessziona=new LatLng(31.926597,34.800077);
    mMap = googleMap;
 mMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
        mMap.addMarker(new MarkerOptions()
                .position(nessziona)
                .title("Hello world"));
    mMap.moveCamera((CameraUpdateFactory.newLatLng(nessziona,17f)));
} 

XML:


0
qo'shib qo'ydi