PDA

View Full Version : Dispay marker on Current position of user at map



msench
10 Mar 2013, 10:39 PM
I am able to display map on screen and get the current positions of latitude and longitude. However I want to display a marker at the position of those latitude and longitude values. I have tried by adding a listener when map is rendered. Below is the code. But no marker shows up on the screen. Any pointers on how to get the marker displayed at the current position will be really helpful..





<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Secha</title>

<script src="touch/sencha-touch-all.js" type="text/javascript"></script>
<script src="http://maps.googleapis.com/maps/api/js?sensor=true"></script>
<link href="touch/resources/css/sencha-touch.css" rel="stylesheet" type="text/css" />

<script type="text/javascript">
Ext.application({
name: 'MapApp',

launch: function() {
var lat,lng;

//get latitude and longititude values

Ext.device.Geolocation.getCurrentPosition({
success: function(position) {
lat = position.coords.latitude;

lng = position.coords.longitude;
alert(lat);
alert(lng);
Ext.Viewport.add( {
xtype:'map',
useCurrentLocation:true,
fullscreen: true,
layout:'fit',
listeners : {
maprender : function() {
alert('map rendered');
var marker = new google.maps.Marker({
position: new google.maps.LatLng(lat,lng),
title : 'testing',

});
}
}

});
},
failure: function() {
alert('something went wrong!');
}
});
}
});


</script>
</head>
<body></body>


</html>

mitchellsimoens
12 Mar 2013, 12:27 PM
The Geolocation class that is being used to get the current position is on the map via the getGeo method. From that Geolocation class you can get the coords.

msench
12 Mar 2013, 10:11 PM
I have already got the coordinates. However this was due to missing map attribute in function being called on maprender.