How can I get a marker at the current location on the map in Sencha-Touch2.0

Hi friends, I am new to Sencha Touch platform .

And I want to find the current location user with marker , please help me. I am stuck in this condition.

Is there a new good tutorial for me, please share with me ..

Thanks at Advance for your time.

Ravi Patel

+6
source share
3 answers

Good question. I used to run into a similar problem. But later I realized the solution.

Here is how you can solve it.

Demo with the Phonebook Geolocation API

  • Get geolocation using 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'); } 
  • Then use the lat and lng values ​​to set the center of the map for it, and also set this value for the marker position.

      ... ... 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 }); ... ... 
+4
source

This is much 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()); 

While you are creating your map, it should get the current location if the browser client allows you to get this.

NTN!

0
source

I also work for a simillar application using sencha touch 2.3.1
Using the Ext.util.Geolocation class to get the current location and automatically update 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 already used in my application to get currentLocation and moved the marker to currentPosition.

0
source

Source: https://habr.com/ru/post/914222/


All Articles