1

我能够获得当前位置点。现在我想在地图上显示这个点(经度和纬度)。

if(Ti.Network.online){
        Ti.Geolocation.purpose = "Receive User Location";
        Titanium.Geolocation.getCurrentPosition(function(e){

            if (!e.success || e.error)
            {
                alert('Could not find the device location');
                return;
            }
            var longitude = e.coords.longitude;
            var latitude = e.coords.latitude;

            alert("latitude: " + latitude + "longitude: " + longitude);

        });
    }else{
        alert("Internet connection is required to use localization features");
    }
4

2 回答 2

0

https://github.com/appcelerator/KitchenSink/blob/master/Resources/ui/common/phone/geolocation.js

运行它,它将为您提供 android 和 iOS 的经度和纬度

谢谢

于 2013-09-10T01:49:38.810 回答
0

看看这个简单的例子。如果您不想添加注释,那么 setRegion 可能就是您要查找的内容。

// Create a simple fullscreen map and add an annotation to it
// This example assumes you have a window called "win"

// Our lat/lng fake data
var latitude = 11.11111;
var longitude = 11.11111;

// Create Map View
// For more information on Map Views refer to:
// http://docs.appcelerator.com/titanium/3.0/#!/api/Titanium.Map-method-createView
var mapView = Titanium.Map.createView({
    top          : 0,
    left         : 0,
    bottom       : 0,
    right        : 0,
    mapType      : Titanium.Map.STANDARD_TYPE,
    animate      : true,
    regionFit    : true,
    userLocation : true,
    touchEnabled : true
});
win.add(mapView);

// Create an annotation with a right button
// For more information on annotations refer to:
// http://docs.appcelerator.com/titanium/3.0/#!/api/Titanium.Map-method-createView
var annotation = Ti.Map.createAnnotation({
    latitude    : latitude,
    longitude   : longitude,
    title       : 'My Annotation',
    subtitle    : 'My Subtitle',
    rightButton : Ti.UI.iPhone.SystemButton.DISCLOSURE
});

// Add this annotation to your map View
// Note that this is an array, you can add more
// than one annotation at a time
mapView.setAnnotations([annotation]);

// Set the region of your map
// that is, zoom to where our annotation is
var region = {
    latitude       : latitude,
    longitude      : longitude,
    animate        : true,
    latitudeDelta  : 0.005,
    longitudeDelta : 0.005
};
mapView.setRegion(region);

// Check if our annotation is clicked
mapView.addEventListener('click', function(e) {
    if(e.clicksource === 'rightButton') {
        // Do something here
    };
});

这或多或少与 Appcelerators 自己的示例相同: http ://docs.appcelerator.com/titanium/3.0/#!/api/Titanium.Map-method-createAnnotation

于 2013-09-11T10:49:05.190 回答