Select to view content in your preferred language

Hello i am working with java desktop application and want to plot a point in arcgis map using google lat long. I am using mmpk file to load offline map in java but unable to put marker on correct location. can you please tell me how to convert google lat

630
1
09-30-2018 05:20 AM
NishantRaju
New Contributor

public class Map1 extends Application {
private MapView mapView;
static MainApplication mm ;
private ArcGISTiledLayer tiledLayer;
ArrayList mainList=new ArrayList();
ArcGISMap mapp;
@Override
public void start(Stage stage) {
String latt="76.8467,95.9462",lonn="26.9234,81.9573";

try {
if(mainList.size()<=0)
{
String lat1="26.990237,80.768091",lat2="26.9234,81.9573";
mainList.add(lat1);
mainList.add(lat2);

}
// create stack pane and application scene
StackPane stackPane = new StackPane();
Scene scene = new Scene(stackPane);

// set title, size, and add scene to stage
stage.setTitle("Open Mobile Map Package Sample");
stage.setWidth(800);
stage.setHeight(700);
stage.setScene(scene);
stage.show();

// create a map view
mapView = new MapView();

//load a mobile map package
final String mmpkPath = new File("C:/sqlite/Map.mmpk").getAbsolutePath();
MobileMapPackage mobileMapPackage = new MobileMapPackage(mmpkPath);

mobileMapPackage.loadAsync();
mobileMapPackage.addDoneLoadingListener(() -> {
if (mobileMapPackage.getLoadStatus() == LoadStatus.LOADED && mobileMapPackage.getMaps().size() > 0) {
//add the map from the mobile map package to the map view
mapp=mobileMapPackage.getMaps().get(0);


int index=latt.indexOf(",");

double latd=Double.parseDouble(latt.substring(0,index));
double lond=Double.parseDouble(latt.substring(index+1,latt.length()));
//MapPoint mpLatLon = Esri.ArcGISRuntime.Geometry.GeometryEngine.Project(mapPointObjectToConvert, SpatialReferences.Wgs84) as MapPoint;

final SpatialReference webMercator =SpatialReference.create(4326);;
Point p=new Point(lond,latd, SpatialReference.create(102113));
Point pointGeometry = (Point) GeometryEngine.project(23.63733,37.94721, SpatialReference.create(102113));


Point pp = (Point)GeometryEngine.project(p, SpatialReference.create(102113) );


Thread th=new Thread(new Runnable(){

@Override
public void run() {
// TODO Auto-generated method stub
Viewpoint viewpoint = new Viewpoint(g, 75000);
mapp.setInitialViewpoint(viewpoint);


mapView.setMap(mapp);
GraphicsOverlay graphicsOverlay = new GraphicsOverlay();
mapView.getGraphicsOverlays().add(graphicsOverlay);

// set initial view point to the ArcGISMap
SimpleMarkerSymbol symbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.Style.DIAMOND, 0xFFFF0000, 12);
Graphic graphic = new Graphic(g, symbol);
graphicsOverlay.getGraphics().add(graphic);

}});
th.start();

} else {
Alert alert = new ;
alert.show();
}
});

// add the map view to stack pane

stackPane.getChildren().add(mapView);
} catch (Exception e) {
// on any error, display the stack trace.
infoBox(String.valueOf(e),"Error");
e.printStackTrace();
}
}


/**
* Stops and releases all resources used in application.
*/
@Override
public void stop() {

if (mapView != null) {
mapView.dispose();
}
}

/**
* Opens and runs application.
*
* @param args arguments passed to this application
// */
public static void main(String[] args) {

Application.launch(args);
}
public static void infoBox(String infoMessage, String titleBar)
{
JOptionPane.showMessageDialog(null, infoMessage, "InfoBox: " + titleBar, JOptionPane.INFORMATION_MESSAGE);
}

}

 //////////////////////////////

I want to put marker from google lattitude and longitude.

0 Kudos
1 Reply
ColinAnderson1
Esri Contributor

I think all you need to do is to use Graphic (double latitude, double longitude) which will create a graphic from your lat, lon point. The graphic should automatically re-project to match your map when you add it to the graphics overlay.

Something like...

SimpleMarkerSymbol symbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.Style.DIAMOND, 0xFFFF0000, 12);
Graphic graphic = new Graphic(lat, lon); 
graphicsOverlay.getGraphics().add(graphic);
0 Kudos