离子2地图加载"未捕获(承诺):[对象位置错误]"

时间:2017-05-15 10:34:43

标签: google-maps ionic2

  File "/usr/lib/python2.7/pickle.py", line 331, in save
  self.save_reduce(obj=obj, *rv)
  File "/usr/lib/spark/python/lib/pyspark.zip/pyspark/cloudpickle.py", 
  line 553, in save_reduce
  File "/usr/lib/python2.7/pickle.py", line 286, in save
  f(self, obj) # Call unbound method with explicit self
  File "/usr/lib/python2.7/pickle.py", line 649, in save_dict
  self._batch_setitems(obj.iteritems())
  File "/usr/lib/python2.7/pickle.py", line 681, in _batch_setitems
  save(v)
  File "/usr/lib/python2.7/pickle.py", line 286, in save
  f(self, obj) # Call unbound method with explicit self
  File "/usr/lib/spark/python/lib/pyspark.zip/pyspark/cloudpickle.py", 
  line 582, in save_file
  pickle.PicklingError: Cannot pickle files that are not opened for reading

2 个答案:

答案 0 :(得分:3)

您需要捕获错误并对其执行某些操作。为此,需要添加错误捕获。修复问题的代码在这里:

initMap(): Promise<any> {
    this.mapInitialised = true;//part 1
    return new Promise((resolve) => {
        this.geolocation.getCurrentPosition().then(
            (position) => {// Part 2
            let latLng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
            let mapOptions = {
                center: latLng,
                zoom: 15,
                mapTypeId: google.maps.MapTypeId.ROADMAP;
            }

            this.map = new google.maps.Map(this.mapElement, mapOptions);
            resolve(true);
        },
        // Here is the error catching that needs to be added
        err =>{
             console.log(' Error : ' + JSON.stringify(error));
        });
    });
}

答案 1 :(得分:2)

建议您尝试将错误视为:

this.geolocation.getCurrentPosition().then(
(position) => {  
    /* your code */
} err =>{
      alert('Error message : '+ err.message);
 });

通过执行此操作,您将收到正确的错误消息。