6

Hey friends i m new to Sencha Touch platform.

And I want to find user current location with marker please help me out. i stuck in this condition.

Is there any new good tutorial for me then please share with me..

Thanks in Advance for your time.

Ravi Patel

Ravi Patel
  • 63
  • 2
  • 5

3 Answers3

4

Nice question. I faced a similar problem before. But, later, I figured out the solution.

Here's how you can solve it.

Demo with Phonegap's Geolocation API

  1. Get the geolocation via the geolocation api.

    vat lat, lng;
    var geoLocationOptions = { maximumAge: 3000, timeout: 5000, enableHighAccuracy: true };
    navigator.geolocation.getCurrentPosition(geoLocationSuccess,geoLocationError,geoLocationOptions);
    
    function geoLocationSuccess(position) {
        lat = position.coords.latitude;
        lng = position.coords.longitude;
        Ext.Msg.alert("Geolocation","Latitude:"+ lat +", Longitude:"+ lng); 
    }
    
    function geoLocationError() {
       Ext.Msg.alert('Error','Error while getting geolocation');
    }
    
  2. Then use the values of lat and lng to set the map's center to it as well as set the marker's position to that value.

     ... 
     ...
     var position = new google.maps.LatLng(lat,lng);
     map = this.add({
            xtype: 'map',
            getLocation: true,
            autoLoad: true,
            mapOptions: {
                zoom: 15,
                center: position,
                mapTypeId: google.maps.MapTypeId.ROADMAP,
                navigationControl: true,
                zoomControl: true,
                mapTypeControl: true,
                scrollwheel: true,
                scaleControl: true,
                zoomControlOptions: {
                    style: google.maps.ZoomControlStyle.LARGE
                }
            }
        });
    
     marker = new google.maps.Marker({
            id: 'geoLocMarker',
            position: position,
            map: map.getMap(),
            visible: true
     });
     ...
     ...
    
Saurabh Gokhale
  • 53,625
  • 36
  • 139
  • 164
  • Thank's For u'r Time,I had Tried Above code .But,It Didn't work. I want to Implement in Sencha touch2.0...if above code is worked then can you pls tell me how can i implemetn it ? – Ravi Patel Apr 27 '12 at 06:00
  • the above code where i want to excatly add..and can you please elobrate the structure wise..... – Ravi Patel Apr 30 '12 at 11:48
  • thankx for u'r help....i had tried ,but still not worked....can u Please send me demo on my emial....i am very thankful to u.... – Ravi Patel Apr 30 '12 at 12:08
  • You please post the entire code of your that map view here. That will help rectify your problem. – Saurabh Gokhale Apr 30 '12 at 12:12
  • Please send me demo on my email at ravip.cenrix@gmail.com – Ravi Patel Apr 30 '12 at 12:18
  • can u send me u'r email id...that's wahy i send my whole code – Ravi Patel May 01 '12 at 06:23
  • I have been trying the same code in Sencha touch. However the control does not go into geoLocationSuccess() function and always returns error from geoLocationError(). What could be the possible cause for this? – sandy Mar 11 '13 at 02:53
0

It's a lot simpler if you just use Ext.Map.getGeo() as follows:

    var geo = extmap.down("#Map").getGeo();
    var currentPosition = new google.maps.LatLng(geo.getLatitude(), geo.getLongitude());

As long as you have your map instantiated, it should get the current location if the browser client allows for you to obtain that.

HTH!

occasl
  • 5,303
  • 5
  • 56
  • 81
0

I have also work for simillar app using sencha touch 2.3.1
Using Ext.util.Geolocation class for get current location and automatically update the currentPosition using the following code.

Ext.create('Ext.util.Geolocation', {
autoUpdate: true,
allowHighAccuracy: true,
frequency: '5000', // set the milliseconds for the location update
listeners: {
locationupdate: function(geo) {
    latitude=Global.currentUserLocations.currentLat;
    longitude=Global.currentUserLocations.currentLong;
    if(Global.currentUserPositionMarker)
    {
        latlng1=new google.maps.LatLng(latitude, longitude);
        Global.currentUserPositionMarker.setPosition(latlng1);
    }
   }
 }
});  

The above code worked for me and i have already used in my app for getting currentLocation and moved the marker into currentPosition.

Nayan Dabhi
  • 986
  • 9
  • 20