代码之家  ›  专栏  ›  技术社区  ›  Marc

钛移动销坐标

  •  1
  • Marc  · 技术社区  · 7 年前

    在我移动了地图上的大头针后,我正在尝试获取坐标。我使用了用户当前位置,当我打开地图时,地图显示正确。但是,当我将pin移动到另一条街道时,将无法使新的coords仍然显示相同的coords。

    这是我的密码

    var Map = require('ti.map');
    
    if(Ti.Geolocation.locationServicesEnabled){
    
    Ti.Geolocation.addEventListener('location', function(e) {
    
        if (e.error){
    
            alert('Error: ' + e.error);
    
        }else {
            longitude = e.coords.longitude;
            latitude = e.coords.latitude;
    
    
    
    var mapView = Map.createView({
    top          : 0,
    left         : 0,
    bottom       : 0,
    right        : 0,
    mapType      : Map.STANDARD_TYPE,
    animate      : true,
    regionFit    : true,
    userLocation : false,
    touchEnabled : true,
    draggable    : true
    });
    
    
    
    view3.add(mapView);
    view3.add(boton2);
    
    var annotation = Map.createAnnotation({
    latitude    : latitude,
    longitude   : longitude,
    title       : 'Selecciona Tu Ubicación',
    draggable   : true
    });
    
    mapView.setAnnotations([annotation]);
    
    var region = {
    latitude       : latitude,
    longitude      : longitude,
    animate        : true,
    latitudeDelta  : 0.005,
    longitudeDelta : 0.005
    };
    mapView.setRegion(region);
    
    mapView.addEventListener('pinchangedragstate', function(e) {
        Ti.API.info(longitude + ' - ' + latitude);
    }); 
        }
    
    });
    
    }else{
    
    alert('Por favor habilita los servicios de ubicación');
    }
    

    谢谢

    1 回复  |  直到 7 年前
        1
  •  0
  •   Rene Pot    7 年前

    您正在记录手动设置的变量,这些变量不会自动更改。您必须使用注释来检查坐标。

    如果你看看 documentation 对于事件,您将看到注释也返回到那里。

    mapView.addEventListener('pinchangedragstate', function(e) {
        Ti.API.info(e.annotation.longitude + ' - ' + e.annotation.latitude);
    });