Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
private void setMap(String x, String y, Integer width, Integer height) throws Exception {
        if (this.ApiKey.isEmpty()) {
            throw new Exception("Developper API Key not set !!!!");
        }
Dimension dimension = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
            int hz2 = (int)dimension.getHeight();
            int hz1  = (int)dimension.getWidth();
 
        String url = "http://maps.googleapis.com/maps/api/staticmap?center=milano&zoom=5&size";
 
  url+="?center=milano&zoom=5&size="+(hz1-(hz1/5))+"x"+(hz2-100)+"&maptype=roadmap&"
    +"&markers=color:green%7Clabel:G%7C49.260242,10.676406sensor=false"                     
+"&path=color:0xff0000ff|weight:3|49.260767, 10.542647|4789,5.365397&sensor=false";
C'est une URL d'une MAP statique qui est traitée comme une chaîne de caractère. Je veux une classe en Java ou une méthode qui traite les URL comme étant une chaine. Les choses qui changent dans l'URL sont les coordonnées x et y qui sont dans notre l'exemple ci-dessus (49.260242,10.676406).

La classe doit lire les nouvelles coordonnées à chaque fois à partir d'un fichier et il l'affecte dans la nouvelle chaîne et puis il importe la nouvelle image avec des marqueurs placés selon les nouvelles coordonnées.

Le problème est de découper l'url en des chaines puis les rassembler dans une nouvelle chaines et la lecture des x et y a partir d'un fichier (qui va jouer le rôle d'un similateur ). Et surtout comment lire les nouveaux x et y et les placer dans l 'url qui sert a tracer dans la nouvelle image ?

Voila le code complet :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
package usdc;
 
import java.awt.Dimension;
import javax.swing.JEditorPane;
import javax.swing.text.html.HTMLDocument;
import javax.swing.text.html.HTMLEditorKit;
 
/**
 * Afficher une carte GoogleMap dans un JEditorPane
 * @author fobec 2010
 */
public class JGoogleMapEditorPan extends JEditorPane {
 
    private int zoomFactor = 7;
    private String ApiKey = "";
    private String roadmap = "roadmap";
    public final String viewTerrain = "terrain";
    public final String viewSatellite = "satellite";
    public final String viewHybrid = "hybrid";
    public final String viewRoadmap = "roadmap";
 
    /**
     * Constructeur: initialisation du EditorKit
     */
    public JGoogleMapEditorPan() {
        HTMLEditorKit kit = new HTMLEditorKit();
        HTMLDocument htmlDoc = (HTMLDocument) kit.createDefaultDocument();
        this.setEditable(false);
        this.setContentType("text/html");
        this.setEditorKit(kit);
        this.setDocument(htmlDoc);
    }
 
    /**
     * Fixer le zoom
     * @param zoom valeur de 0 à 21
     */
    public void setZoom(int zoom) {
        this.zoomFactor = zoom;
    }
 
    /**
     * Fixer la clé de developpeur
     * @param key APIKey fourni par Google
     */
    public void setApiKey(String key) {
        this.ApiKey = key;
    }
 
    /**
     * Fixer le type de vue
     * @param roadMap
     */
    public void setRoadmap(String roadMap) {
        this.roadmap = roadMap;
    }
 
    /**
     * Afficher la carte d'après des coordonnées GPS
     * @param latitude
     * @param longitude
     * @param width
     * @param height
     * @throws Exception erreur si la APIKey est non renseignée
     */
    public void showCoordinate(String latitude, String longitude, int width, int height) throws Exception {
        this.setMap(latitude, longitude, width, height);
    }
 
    /**
     * Afficher la carte d'après une ville et son pays
     * @param city
     * @param country
     * @param width
     * @param height
     * @throws Exception erreur si la APIKey est non renseignée
     */
    public void showLocation(String city, String country, int width, int height) throws Exception {
        this.setMap(city, country, width, height);
    }
 
    /**
     * Assembler l'url et Générer le code HTML
     * @param x
     * @param y
     * @param width
     * @param height
     * @throws Exception
     */
    private void setMap(String x, String y, Integer width, Integer height) throws Exception {
        if (this.ApiKey.isEmpty()) {
            throw new Exception("Developper API Key not set !!!!");
        }
Dimension dimension = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
            int hz2 = (int)dimension.getHeight();
            int hz1  = (int)dimension.getWidth();
 
        String url = "http://maps.googleapis.com/maps/api/staticmap";
 
  url+="?center=milano&zoom=5&size="+(hz1-(hz1/5))+"x"+(hz2-100)+"&maptype=roadmap&"
+"&markers=color:yellow%7Clabel:G%7C43.304789,5.365397&sensor=false";
   url += "center=" + x + "," + y;
        url += "&zoom=" + this.zoomFactor;
        url += "&size=" + width.toString() + "x" + height.toString();
        url += "&maptype=" + this.roadmap;
        url += "&markers=color:blue" + x + "," + y;
        url += "&sensor=false";
        url += "&key=" + this.ApiKey;
        String html = "<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN'>";
        html += "<html><head></head><body>";
        html += "<img src='" + url + "'>";
        html += "</body></html>";
              this.setText(html);
    }}
 
 
    /**
     * Exemple : JGoogleMapEditorPan dans un JFrame
     */
    /*public static void main(String[] args) {
    JGoogleMapEditorPan googleMap = new JGoogleMapEditorPan();
        try {
            googleMap.setApiKey("maCleGoogleMap");
            //  googleMap.setRoadmap(googleMap.viewHybrid);
 
            /**
            Afficher la ville de Strabourg
             
            googleMap.showLocation("strasbourg", "france", 390, 400);
            /**
             * Afficher Paris en fonction ses coordonnées GPS
             
            //  googleMap.showCoordinate("48.8667", "2.3333",390, 400);
        } catch (Exception ex) {
            Logger.getLogger(JGoogleMapEditorPan.class.getName()).log(Level.SEVERE, null, ex);
        }
 
        JPanel frame = new JPanel();
        
       // frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.add(googleMap);
        frame.setSize(400, 420);
        frame.setLocation(200, 200);
        frame.setVisible(true);
        
    
    }*/