cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - When posting, your subject should be specific and summarize your question. Here are some additional tips on asking a great question. X

Location Geocode

jw614h
1-Newbie

Location Geocode

I mapping all the organizations in or sandbox.

Here is a snippet of the code:

def organizationBridge = Bridges.getOrganizationBridge();

def locationBridge = Bridges.getLocationBridge();

def orgResults = organizationBridge.find(new OrganizationCriteria());

def orgs = orgResults.getOrganizations();

def locations;

def locationRef;

def location;

try{

    orgs.each() {

        locations = it.getLocations();

        locSize = locations.size() ?: 0;

        if (locSize > 0){

            locationRef = locations.get(0);

            location = locationBridge.findById(locationRef.getSystemId());

            geocode = location.getGeocode() ?: "0,0";

            geocodeList = Arrays.asList(geocode.split("\\s*,\\s*"));

            row.put("Latitude", geocodeList.get(0));

            row.put("Longitude", geocodeList.get(1));

        }

        rows.push(row);

        row = new HashMap();

    }

}catch(Exception e)

{

    bSuccess = false;

}

 

Sometime getGeocode() returns a null.

How does the system know the geocode of the address?

Is there a way to refresh or update the geocodes?

Thanks

Jay

1 ACCEPTED SOLUTION

Accepted Solutions
jw614h
1-Newbie
(To:jw614h)

I figured out how to accomplish this from the API doc

You need to pass in the Organization ID(orgId) and the new geocode(newgeocode as lat,long) :


import groovy.json.JsonBuilder;


import groovy.json.JsonSlurper;


import com.axeda.sdk.v2.dsl.Bridges;


import com.axeda.sdk.v2.bridge.LocationBridge;


import com.axeda.services.v2.LocationCriteria;



HashMap root = new HashMap();


List rows = new ArrayList();


HashMap row = new HashMap();



def organizationBridge = Bridges.getOrganizationBridge();


def org = organizationBridge.findById(parameters.orgId);


def locationBridge = Bridges.getLocationBridge();


locations = org.getLocations();


locSize = locations.size() ?: 0;


row.put("ClientId", org.getSystemId());


row.put("ClientName", org.getLabel());


if (locSize > 0){


    locationRef = locations.get(0);


    location = locationBridge.findById(locationRef.getSystemId());


    geocode = location.getGeocode() ?: "0,0";


    geocodeList = Arrays.asList(geocode.split("\\s*,\\s*"));


    if (geocodeList.get(0) == "0.0" ){


        row.put("update", true);


        location.setGeocode(parameters.newgeocode);


        locationBridge.update(location);


    }


}


root.put("success", true);


root.put("Client", row);


JsonBuilder builder = new JsonBuilder(root);


return ["Content-Type": "application/javascript","Content":builder.toPrettyString()]


View solution in original post

8 REPLIES 8
cdovholuk
6-Contributor
(To:jw614h)

First - if you import the Bridges object statically you can stop def'ing the bridges.  I always start my v2 scripts like this:


import static com.axeda.sdk.v2.dsl.Bridges.*


Then you can simply call 'assetBridge' or 'modelBridge' or whatever bridge you're looking for. I would replace this:


def organizationBridge = Bridges.getOrganizationBridge();


def locationBridge = Bridges.getLocationBridge();


with just that import - it'll work just the same!

As for the .getGeocode() - that *ever* works?  I looked at the object and I don't see a method called getGeocode on the v2 location object at all

It's in the documentation:

https://mentor.axeda.com/javadoc/6_6-SDK_Javadoc/com/axeda/services/v2/Location.html

String getGeocode()

Gets the value of the geocode property.

It brings back comma separated Lat and Long.

It works for some of the locations but not all.

Jay

cdovholuk
6-Contributor
(To:jw614h)

Oh geesh I was looking at the wrong version's javadoc/object. My apologies. There is a periodic task that attempts to do this. It's configured to run on the hour by default but this setting can be modified. Assuming you are hosted by Axeda it would probably be best to check with support to ensure that this task is enabled and what the period is your platform is set to run at.

If that task fails for any reason (maybe the service we use can't find the address etc.) it will leave the address at 0,0.  I would probably recommend you contact support with an address that worked and one that didn't (or many of such addresses) and go from there.

Will do

Thanks

Jay

Location Geocoding is done based on the information included in the location of the asset, is that right?  So if you had an address there that was invalid or unknown to our geocoding service (which I think is open street maps by default since Google charges a commercial fee...) you'd get the 0,0 result.  Am i right?  If so jw614h would also want to check the address for the location on the platform.

If we are using OSM could someone double check if OSM can resolve an address by just going to OpenStreetMap and entering the address there?

Jay - can you post a sample of an address that's failing to Geocode?

Here is one:

909 Covered Bridge Rd, Beatrice, NE 68310

Google geocodes it as :

40.2563868,-96.7189244

Thanks

Jay

Also, is there any way to update the geocode property?

jw614h
1-Newbie
(To:jw614h)

I figured out how to accomplish this from the API doc

You need to pass in the Organization ID(orgId) and the new geocode(newgeocode as lat,long) :


import groovy.json.JsonBuilder;


import groovy.json.JsonSlurper;


import com.axeda.sdk.v2.dsl.Bridges;


import com.axeda.sdk.v2.bridge.LocationBridge;


import com.axeda.services.v2.LocationCriteria;



HashMap root = new HashMap();


List rows = new ArrayList();


HashMap row = new HashMap();



def organizationBridge = Bridges.getOrganizationBridge();


def org = organizationBridge.findById(parameters.orgId);


def locationBridge = Bridges.getLocationBridge();


locations = org.getLocations();


locSize = locations.size() ?: 0;


row.put("ClientId", org.getSystemId());


row.put("ClientName", org.getLabel());


if (locSize > 0){


    locationRef = locations.get(0);


    location = locationBridge.findById(locationRef.getSystemId());


    geocode = location.getGeocode() ?: "0,0";


    geocodeList = Arrays.asList(geocode.split("\\s*,\\s*"));


    if (geocodeList.get(0) == "0.0" ){


        row.put("update", true);


        location.setGeocode(parameters.newgeocode);


        locationBridge.update(location);


    }


}


root.put("success", true);


root.put("Client", row);


JsonBuilder builder = new JsonBuilder(root);


return ["Content-Type": "application/javascript","Content":builder.toPrettyString()]


Top Tags