How do I write to location field in an Entity? I am having a custom entity called Micronews which has a bundle microupdate created in it. I am able to write entity to db for all fields but I am not able to figure out how to write location (using location module). It seems to be stored in db in multiple tables. Is there any standard way to store location to db?

function p_save_entity($name, $issue_type, $constituency, $location){

$name = "Testing programmatically";
$issue_type = "electricity";
$constituency = '22';


$e = entity_create('micronews', array(
    'type' =&gt; 'microupdate',
    'name'=&gt;$name,
    'created'=&gt; time(),

));

$ew = entity_metadata_wrapper('micronews' ,$e);

$ew-&gt;field_type-&gt;set($issue_type);
$ew-&gt;field_constituency-&gt;set($constituency);

$ew-&gt;field_location[latitude]-&gt;set('65.000000');
$ew-&gt;field_location[longitude]-&gt;set('65.000000');

$fl = $ew-&gt;save();

if ($fl){
    return "";
}

else{
    return "Something went wrong";
}


I am using this module.
This works, but (here's the trick), only if you enable the location_entity module, which ships with location.

$location = array(
  'latitude' =&gt; $latitude,
  'street'   =&gt; $street,
  // etc, other elements added here ...
);

$ew-&gt;field_location-&gt;set($location);
$ew-&gt;save();


May no one else lose as much time on this ever again.