mapsplugin / cordova-plugin-googlemaps

Google Maps plugin for Cordova
Apache License 2.0
1.66k stars 914 forks source link

My Location not showing on iOS #300

Closed grzegorzgolec closed 9 years ago

grzegorzgolec commented 9 years ago

On android works perfectly on iOS not showing. Is this option available on iOS ?

wf9a5m75 commented 9 years ago

Could you show me your code? Also is there any error message in xcode error log?

grzegorzgolec commented 9 years ago

Thats my code

I use init function after device is ready

Map.mapObject = plugin.google.maps.Map.getMap();
Map.mapObject.on(plugin.google.maps.event.MAP_READY, function(){

                 Map.mapObject.setMyLocationEnabled(true);
                 Map.mapObject.setOptions({ "camera": {
                    "latLng": new plugin.google.maps.LatLng(Map.startLat,Map.startLng),
                    "zoom": 15
                   }

                 });

});

in different view iam setting the div

               Map.mapObject.setDiv(document.getElementById("map_canvas"));           
               Map.mapObject.refreshLayout();

               Map.mapObject.setVisible(true);

No errors in xcode.

wf9a5m75 commented 9 years ago

What ios version do you use? Also what the map plugin version do you use?

grzegorzgolec commented 9 years ago

iOS 8.1 Map plugin v1.2.4

syahman commented 9 years ago

same error with my cordova project. iOS 7 and iOS 6. Map plugin v1.2.4 cordova ios 3.6.3.

syahman commented 9 years ago

in my case, i resolved it by enabling Google Maps SDK for iOS in Google API Console.

grzegorzgolec commented 9 years ago

In my case it was always on.

TheMassassian commented 9 years ago

Have you tried to set the mapdiv before setting the options?

wf9a5m75 commented 9 years ago

I tested with simple code and I probably understand @grzegorzgolec 's report.

$(document).on('deviceready', function() {
  var map = plugin.google.maps.Map.getMap();
  map.on(plugin.google.maps.event.MAP_READY, function(){

     map.setMyLocationEnabled(true);
     map.setOptions({ "camera": {
        "latLng": new plugin.google.maps.LatLng(35, 137),
        "zoom": 15
       }
     });
  });

  $("#testBtn").click(function() {
    map.setDiv(document.getElementById("map_canvas"));
  });
});

In the above code, map.setMyLocationEnabled() and map.setOptions() do not work properly. Because the map is not displayed even at once. The map plugin passes the statements to Google Maps SDK for iOS (even if you don't display the map), but the map SDK does not work.

In order to solve this, @TheMassassian 's correct way, or execute the statements after the map.setDiv()

  $("#testBtn").click(function() {
    map.setDiv(document.getElementById("map_canvas"));
    map.setMyLocationEnabled(true);
     map.setOptions({ "camera": {
        "latLng": new plugin.google.maps.LatLng(35, 137),
        "zoom": 15
       }
     });
  });