logo
down
shadow

google map marker is not displayed on the map


google map marker is not displayed on the map

By : user2952966
Date : November 19 2020, 03:59 PM
around this issue I'm learning google map API. when i run the app I see the map but I don't see the marker i wait a little time but nothing happen. Here is my code:
code :
public class MapUser extends Fragment implements
    GooglePlayServicesClient.ConnectionCallbacks,
    GooglePlayServicesClient.OnConnectionFailedListener,
    OnMarkerClickListener {
    private Marker myMarker;

@Override
public void onResume() {
    googleMap = mMapFragment.getMap();
    super.onResume();
}

private SupportMapFragment mMapFragment;

@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onActivityCreated(savedInstanceState);
    if (mMapFragment == null) {
        mMapFragment = SupportMapFragment.newInstance();
        FragmentTransaction fragmentTransaction = getChildFragmentManager()
                .beginTransaction();
        fragmentTransaction.add(R.id.content_map, mMapFragment);
        fragmentTransaction.commit();
    }
}

private View rootview;
private LocationClient mLocationClient;

GoogleMap googleMap;

@Override
public View onCreateView(LayoutInflater inflater,
        @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    rootview = inflater.inflate(R.layout.map_app, container,
            false);
    MapsInitializer.initialize(rootview.getContext());
    mLocationClient = new LocationClient(rootview.getContext(), this, this);
    mLocationClient.registerConnectionCallbacks(this);
    mLocationClient.connect();
    return rootview;
}

@Override
public void onConnectionFailed(ConnectionResult result) {
    // TODO Auto-generated method stub

}

@Override
public void onConnected(Bundle connectionHint) {
    // TODO Auto-generated method stub

    try {

        googleMap.setMyLocationEnabled(true);
        googleMap = mMapFragment.getMap();

        Location SS = googleMap.getMyLocation();
        if (SS != null) {
            double lati = SS.getLatitude();
            double longi = SS.getLongitude();
            LatLng latlongs = new LatLng(lati, longi);

            googleMap.addMarker(new MarkerOptions()
                    .position(latlongs)
                    .title("Current Location")
                    .snippet(" ")
                    .icon(BitmapDescriptorFactory
                            .fromResource(R.drawable.mapview)));
        }

        googleMap.setOnMarkerClickListener(this);
        if (googleMap != null) {
            // googleMap.addMarker(new MarkerOptions().position(
            // new LatLng(31.611213, 74.79835)).title("chcek"));
            // googleMap.animateCamera(CameraUpdateFactory.zoomTo(14));
            googleMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);
            googleMap.setMyLocationEnabled(true);
            googleMap.getUiSettings().setZoomControlsEnabled(true);
            googleMap.getUiSettings().setCompassEnabled(false);
            googleMap.getUiSettings().setMyLocationButtonEnabled(true);
            googleMap.getUiSettings().setAllGesturesEnabled(true);
            googleMap.setTrafficEnabled(true);

        }

    } catch (Exception e) {
        e.printStackTrace();
    }

}

@Override
public void onDisconnected() {
}

@Override
public boolean onMarkerClick(Marker marker) {
    // TODO Auto-generated method stub
    LatLng ok = marker.getPosition();
    String userdata = marker.getSnippet();

    double longi = ok.longitude;
    double lati = ok.latitude;
    String longistr = Double.toString(longi);
    String latistr = Double.toString(lati);

    DataBaseHelper obj = new DataBaseHelper(rootview.getContext());
    String cityd = obj.latilangi(latistr, longistr);
    // Toast.makeText(rootview.getContext(),
    // marker.getTitle(), Toast.LENGTH_LONG)
    // .show();
        return true;
}


Share : facebook icon twitter icon
Google Maps API v3 Marker not being displayed

Google Maps API v3 Marker not being displayed


By : Rudra
Date : March 29 2020, 07:55 AM
help you fix your problem I looked at your live source, you need to remove the line marker.setMap(). The marker will already place itself in your map with the map: map property defined above.
Calling setMap would have to be done as marker.setMap(map), but it is redundant and unnecessary because of map: map being in the options. I think what's happening right now is setMap() is interpreted as setMap(null) and the effect is removing your marker.
code :
$(document).ready(function(){
    var myLatLng = new google.maps.LatLng(30.27639, -97.732422);
    var myOptions = {
        center: myLatLng,
        zoom: 16,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    var map = new google.maps.Map(document.getElementById("map-erwincenter"),
            myOptions);
    var marker = new google.maps.Marker({
        position: myLatLng,
        map: map,
        title: "Frank Erwin Center"
    });
    marker.setMap();  // <-- *** This line should disappear ***
});
Google Maps Marker not getting displayed

Google Maps Marker not getting displayed


By : Haen Jose
Date : March 29 2020, 07:55 AM
around this issue The lat, long of San Francisco is 37.7833° N, 122.4167° W according to Google. A longitude on the West should be indicated with a negative sign. So the coordinates should have been something like 37.7750, -122.4183
Google marker is not being displayed on map

Google marker is not being displayed on map


By : xiaobei
Date : March 29 2020, 07:55 AM
I wish this help you Move your marker creation to the initialize function.
$(document).ready(function(){}) works when DOM elements are loaded, which doesn't necessarily mean that the map is loaded. So if you try to create the marker in the document ready function, the map might not be created then, once the map is ready map variable has the map object, so you can make the marker on that, and you can add the markers dynamically after the map is loaded.
code :
var map;
var central_location = new google.maps.LatLng(42.745334, 12.738430);
function initialize() {
  console.log('map loaded');
  var mapCanvas = document.getElementById('map');
  var mapOptions = {
    center: central_location,
    zoom: 14,
    streetViewControl: false,
    mapTypeId: google.maps.MapTypeId.ROADMAP
  }
  map = new google.maps.Map(mapCanvas, mapOptions);
  makePin(42.745334, 12.738430);
}

google.maps.event.addDomListener(window, 'load', initialize);

$(document).ready(function(){
  console.log('document loaded');
})

function makePin(lat, long){
  var marker = new google.maps.Marker({
    position: new google.maps.LatLng(lat, long),
    map: map,
    title: 'This is the title'
  });
  var infowindow = new google.maps.InfoWindow({
    content: '<div>Hello</div>'
  });
  marker.addListener('click', function() {
    infowindow.open(map, marker);
  });
}    
#map {
  width: 500px;
  height: 380px;
}
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" type="text/javascript" style=""></script>
<script src="https://maps.googleapis.com/maps/api/js"></script>
   
<button onclick="makePin(42.749334, 12.739430)">Add Pin</button>
<div id="map"></div>
Google Map marker using JSON. Only the last marker in the loop is displayed on the map

Google Map marker using JSON. Only the last marker in the loop is displayed on the map


By : Bent Mathiesen
Date : March 29 2020, 07:55 AM
I wish this help you I think perhaps the problem is that you are declaring a new map for each marker. I would declare the map once, and reference it for each marker.
Try the following:
code :
<script>
  function myMap() {

        var mapCanvas = document.getElementById("content_map" );
        var mapOptions = {
            center: new google.maps.LatLng(55.812757, -4.195363),
            zoom: 5,
            disableDefaultUI: true,
            styles: [
                  {
                    "elementType": "geometry",

                    "stylers": [
                      {
                        "color": "#f5f5f5"
                      }
                    ]
                  },
                  {
                    "elementType": "labels.icon",
                    "stylers": [
                                  {
                                    "visibility": "off"
                                  }
                                ]
                              },
                              {
                                "elementType": "labels.text.fill",
                                "stylers": [
                                  {
                                    "color": "#616161"
                                  }
                                ]
                              },
                              {
                                "elementType": "labels.text.stroke",
                                "stylers": [
                                  {
                                    "color": "#f5f5f5"
                                  }
                                ]
                              },
                              {
                                "featureType": "administrative.land_parcel",
                                "elementType": "labels",
                                "stylers": [
                                  {
                                    "visibility": "on"
                                  }
                                ]
                              },
                              {
                                "featureType": "administrative.land_parcel",
                                "elementType": "labels.text.fill",
                                "stylers": [
                                  {
                                    "color": "#bdbdbd"
                                  }
                                ]
                              },
                              {
                                "featureType": "poi",
                                "elementType": "geometry",
                                "stylers": [
                                  {
                                    "color": "#eeeeee"
                                  }
                                ]
                              },
                              {
                                "featureType": "poi",
                                "elementType": "labels.text",
                                "stylers": [
                                  {
                                    "visibility": "on"
                                  }
                                ]
                              },
                              {
                                "featureType": "poi",
                                "elementType": "labels.text.fill",
                                "stylers": [
                                  {
                                    "color": "#757575"
                                  }
                                ]
                              },
                              {
                                "featureType": "poi.business",
                                "stylers": [
                                  {
                                    "visibility": "on"
                                  }
                                ]
                              },
                              {
                                "featureType": "poi.park",
                                "elementType": "geometry",
                                "stylers": [
                                  {
                                    "color": "#e5e5e5"
                                  }
                                ]
                              },
                              {
                                "featureType": "poi.park",
                                "elementType": "labels.text",
                                "stylers": [
                                  {
                                    "visibility": "on"
                                  }
                                ]
                              },
                              {
                                "featureType": "poi.park",
                                "elementType": "labels.text.fill",
                                "stylers": [
                                  {
                                    "color": "#0d99ba"
                                  }
                                ]
                              },
                              {
                                "featureType": "road",
                                "elementType": "geometry",
                                "stylers": [
                                  {
                                    "color": "#ffffff"
                                  }
                                ]
                              },
                              {
                                "featureType": "road.arterial",
                                "elementType": "labels",
                                "stylers": [
                                  {
                                    "visibility": "on"
                                  }
                                ]
                              },
                              {
                                "featureType": "road.arterial",
                                "elementType": "labels.text.fill",
                                "stylers": [
                                  {
                                    "color": "#757575"
                                  }
                                ]
                              },
                              {
                                "featureType": "road.highway",
                                "elementType": "geometry",
                                "stylers": [
                                  {
                                    "color": "#9e9e9e"
                                  }
                                ]
                              },
                              {
                                "featureType": "road.highway",
                                "elementType": "labels",
                                "stylers": [
                                  {
                                    "visibility": "on"
                                  }
                                ]
                              },
                              {
                                "featureType": "road.highway",
                                "elementType": "labels.text.fill",
                                "stylers": [
                                  {
                                    "color": "#616161"
                                  }
                                ]
                              },
                              {
                                "featureType": "road.local",
                                "stylers": [
                                  {
                                    "visibility": "off"
                                  }
                                ]
                              },
                              {
                                "featureType": "road.local",
                                "elementType": "labels",
                                "stylers": [
                                  {
                                    "visibility": "off"
                                  }
                                ]
                              },
                              {
                                "featureType": "road.local",
                                "elementType": "labels.text.fill",
                                "stylers": [
                                  {
                                    "color": "#9e9e9e"
                                  }
                                ]
                              },
                              {
                                "featureType": "transit.line",
                                "elementType": "geometry",
                                "stylers": [
                                  {
                                    "color": "#e5e5e5"
                                  }
                                ]
                              },
                              {
                                "featureType": "transit.station",
                                "elementType": "geometry",
                                "stylers": [
                                  {
                                    "color": "#eeeeee"
                                  }
                                ]
                              },
                              {
                                "featureType": "water",
                                "elementType": "geometry",
                                "stylers": [
                                  {
                                    "color": "#0d99ba"
                                  }
                                ]
                              },
                              {
                                "featureType": "water",
                                "elementType": "labels.text.fill",
                                "stylers": [
                                  {
                                    "color": "#9e9e9e"
                                  }
                                ]
                              }
                            ]
        };

        var map = new google.maps.Map(mapCanvas, mapOptions);
        var contentString = '<div id="content">'+

        '<img src="./img/logo_img_map.png" alt="">'+
        '</div>';

        var infowindow = new google.maps.InfoWindow({
          content: contentString
        });


        $.getJSON('data.json', function(json) {



            for (var i = 0; i < json.ChargeDevice.length; i++) { 

                addMarker(json.ChargeDevice[i].ChargeDeviceLocation.Latitude,json.ChargeDevice[i].ChargeDeviceLocation.Longitude);
                console.log(json.ChargeDevice[i].ChargeDeviceLocation.Latitude, json.ChargeDevice[i].ChargeDeviceLocation.Longitude);
            };


            function addMarker(lat,lng) {

                    var image = './img/logo_img_map.png';
                    var marker = new google.maps.Marker({
                        position: new google.maps.LatLng(lat,lng),
                        map: map,
                        icon: image
                    });

            };




      });

    };

  </script>
  <script src="https://maps.googleapis.com/maps/api/js?key=MYKEY"></script>
Google Maps API for iOS - Marker is not displayed

Google Maps API for iOS - Marker is not displayed


By : user3454931
Date : March 29 2020, 07:55 AM
I wish this helpful for you I think the code is okay, but the marker is not visible because it is in another part of the world. Try to exchange latitude and longitude of your marker marker.position = CLLocationCoordinate2D(latitude: 13.9553836,longitude: 48.1956954)
Or set a lower zoom to your map
Related Posts Related Posts :
  • FastAdapter: Undo button does not show up after swipe
  • What are reasons to pass getActivity as the LifecycleOwner to the LiveData's observe method in a fragment?
  • Implement Face Recognition in Android
  • Titanium studio cannot run "titanium" command in terminal
  • How to execute command line ffmpeg commands programatically in android?
  • Make Android List Items clickable with each item pointing to a different link
  • listview runs successfully, but nothing is display in emulator
  • How to zoom in a bitmap with high resolution?
  • Passing listView data through intent
  • Google map route direction show by arrows in android v2
  • how to start "uiautomator test run" from android code?
  • Proguard in Android Library
  • Alarm Clock from GIT - Gives error - Android
  • Mock injection using Mockito - Android
  • Get Bitmap from universal image loader
  • Unable to include custom font in android
  • Basics on using logcat in Android development
  • Android: Clear cache programmatically
  • Android: pass object without serialization
  • Can not scroll and click item on gridview inside scrollview
  • Android device keeps disconnecting from adb / eclipse
  • Volley cannot create cache directory. Could not clean up file
  • ShareActionProvider icon in actionbar
  • How to open a custom attachment using an Android app?
  • Unable to add column dynamically into the sqlite table
  • android persistence activity which never stop
  • The Google Play services resources were not found. Check your project configuration to ensure that the resources are inc
  • How to select files from google drive in android?
  • Run a AsyncTask every 10 seconds until cancelled
  • Blur on touch. Android application
  • NDK Android - Can't build ARMv5 and V7 at the same time
  • Android development with Eclipse clean and build
  • How to set Different Key Background for every Key in Android Custom Keyboard
  • Face recognition using OpenCV in android?
  • Tumblr API - Jumblr for Android [OAuthConnectionException]
  • Small Icon on Notification not working correctly
  • ConstraintLayout match parent height on larger screens but scroll on smaller
  • Kotlin version issue
  • How can i make my android app look the same on RTL and LTR languages?
  • Can not detect Android NDK toolchain
  • Falling back on PROMPT mode since _cordovaNative is missing. Expected for Android 3.2 and lower only.
  • Facebook Key Hash for Play Store Release
  • backbutton confirm exit app android + phonegap + jquery
  • How to Make Instagram Listview in android?
  • Up and Down Enemy Movement using translate corona sdk
  • Set selection method is not working in gallery in android
  • How to implement onOptionsItemSelected for Sub-Menu Items?
  • HttpHostConnectException connection refused ConnectException ErrnoException
  • Adding Buttons to expendableListView as last Child
  • Android. Block phone on startup
  • How to programmatically check If string is not to wide to fit onto the screen in Android
  • EditText box cursor appear after touching box?
  • using if statement when video is done playing
  • Add to Aspectpath not found MonkeyTalk
  • GooglePlusUtil cannot be resolved (Android)
  • Trouble understanding Relative Layout
  • How to title/name each fragment separately to appear on PagerTitleStrip?
  • Android webView blinks
  • Available service types in WifiP2pDnsSdServiceInfo.newInstance
  • Hide only bottom action bar Android
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org